-
Notifications
You must be signed in to change notification settings - Fork 24
/
cli.js
executable file
·40 lines (32 loc) · 1.11 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
38
39
40
#!/usr/bin/env node
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { program } from 'commander';
import optimizt from './index.js';
const dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(await fs.readFile(path.join(dirname, 'package.json')));
program
.option('--avif', 'create AVIF and exit')
.option('--webp', 'create WebP and exit')
.option('-f, --force', 'force create AVIF and WebP')
.option('-l, --lossless', 'perform lossless optimizations')
.option('-v, --verbose', 'be verbose')
.option('-c, --config <path>', 'use this configuration, overriding default config options if present')
.option('-o, --output <path>', 'write output to directory');
program
.usage('[options] <dir> <file ...>')
.version(packageJson.version, '-V, --version')
.description(packageJson.description)
.parse(process.argv);
if (!program.args.length) {
program.help();
} else {
optimizt({
paths: program.args,
...program.opts(),
});
}
process.on('unhandledRejection', error => {
console.error(error);
});