-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
36 lines (32 loc) · 1.12 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
#!/usr/bin/env node
const path = require("path");
const program = require("@caporal/core").default;
const { runChecker } = require("./checker");
const { MAX_COMPRESSION_DIFFERENCE_PERCENTAGE } = require("./constants");
program
.version("0.0.0")
.option("--cwd <path>", "Explicit current-working-directory", {
validator: program.PATH,
default: path.join(process.cwd(), ".."),
})
.option(
"--max-compression-difference-percentage <amount>",
"Max percentage for reduction after compression",
{ validator: program.FLOAT, default: MAX_COMPRESSION_DIFFERENCE_PERCENTAGE }
)
.option("--save-compression", "If it can be compressed, save the result", {
validator: program.BOOL,
})
.argument("[files...]", "list of files to check")
.action(({ args, options }) => {
const cwd = options.cwd || process.cwd();
const allFilePaths = (args.files || []).map((f) => path.resolve(cwd, f));
if (!allFilePaths.length) {
throw new Error("no files to check");
}
return runChecker(allFilePaths, options).catch((error) => {
console.error(error);
process.exit(1);
});
});
program.run();