Update dependency: globby to 12.0.2.

This commit is contained in:
David Anson 2021-12-27 22:40:44 +00:00 committed by GitHub
parent 05b9e6e43c
commit 11e9a20531
4 changed files with 29 additions and 24 deletions

View file

@ -2,20 +2,27 @@
"use strict";
const fs = require("fs");
const globby = require("globby");
const fs = require("fs").promises;
const [ command, ...args ] = process.argv.slice(2);
if (command === "copy") {
const [ src, dest ] = args;
fs.copyFileSync(src, dest);
} else if (command === "delete") {
for (const arg of args) {
for (const file of globby.sync(arg)) {
fs.unlinkSync(file);
}
// eslint-disable-next-line unicorn/prefer-top-level-await
(async() => {
if (command === "copy") {
const [ src, dest ] = args;
await fs.copyFile(src, dest);
} else if (command === "delete") {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const { globby } = await import("globby");
await Promise.all(
args.flatMap(
(glob) => globby(glob)
.then(
(files) => files.map((file) => fs.unlink(file))
)
)
);
} else {
throw new Error(`Unsupported command: ${command}`);
}
} else {
throw new Error(`Unsupported command: ${command}`);
}
})();