Skip to content

Commit

Permalink
Pass COPYFILE_FICLONE to fs.copyFile in npm script helper for better …
Browse files Browse the repository at this point in the history
…file copy performance where possible.
  • Loading branch information
DavidAnson committed Jan 5, 2025
1 parent 63271e1 commit e6af112
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/index.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// @ts-check

import fs from "node:fs/promises";
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import { constants, copyFile, rm, unlink } from "node:fs/promises";
import { globby } from "globby";

const [ command, ...args ] = process.argv.slice(2);

if (command === "copy") {
const [ src, dest ] = args;
await fs.copyFile(src, dest);
await copyFile(src, dest, constants.COPYFILE_FICLONE);
} else if (command === "delete") {
await Promise.all(
args.flatMap(
(glob) => globby(glob)
.then(
(files) => files.map((file) => fs.unlink(file))
(files) => files.map((file) => unlink(file))
)
)
);
} else if (command === "remove") {
await Promise.all(args.map((dir) => fs.rm(dir, { "recursive": true })));
await Promise.all(args.map((dir) => rm(dir, { "recursive": true })));
} else {
throw new Error(`Unsupported command: ${command}`);
}

0 comments on commit e6af112

Please sign in to comment.