-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·37 lines (32 loc) · 1.48 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
const startTime = performance.now();
import program from 'commander';
import { performance } from 'perf_hooks';
import { cachekill } from './lib/esm/cachekill.js';
program
.version('3.0.2', '-v, --version', 'Outputs the current version number')
.requiredOption('-s, --source <files...>', 'Source file(s); a fingerprinted copy will be generated for each of them')
.option('-t, --target <files...>', 'Target file(s); files with references to source files to be replaced')
.option('-l, --length <length>', 'Length of the fingerprint (between 1-32); longer means less colisions (defaults to 32)')
.option('-p, --pattern <pattern>', 'Pattern for the fingerprinted filenames; defaults to {name}-{hash}{ext}')
.option('-r, --rename', 'Rename source files with the fingerprint instead of generating copies; ignores')
.option('-q, --quiet', 'Supresses console output')
.helpOption('-h, --help', 'Displays usage information')
.parse(process.argv)
const opts = program.opts();
const result = await cachekill(
opts.source,
opts.target,
opts.length,
opts.rename,
opts.pattern
);
if (!opts.quiet) {
const operation = opts.rename ? 'renamed:' : 'copied:';
for (const obj of result.sourcePaths) {
console.log(operation, obj.path, '-->', obj.newPath);
}
const elapsedTime = Math.round(performance.now() - startTime);
const targetCount = result.targetPaths ? result.targetPaths.length : 0;
console.log(`${targetCount} target file(s) updated in ${elapsedTime}ms`);
}