-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·70 lines (58 loc) · 1.75 KB
/
Copy pathcli.js
File metadata and controls
executable file
·70 lines (58 loc) · 1.75 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
/* eslint-disable no-console */
import chalk from 'chalk';
import meow from 'meow';
import { linemod } from 'linemod-core';
const cli = meow(`
Usage
$ linemod -e <output file extension> <path to files, separated by spaces>
Applies linemods to all listed files and outputs them to their current location with their file extensions replaced by the specified one.
Options
-e, --extension Required. The file extension used for the output files.
-v, --verbose Shows warnings and notices.
--help Print this help and exits.
--version Prints current version and exits.
Examples
$ linemod -e mjs index.js lib/utils.js
`, {
importMeta: import.meta,
flags: {
extension: {
shortFlag: 'e',
type: 'string',
},
verbose: {
shortFlag: 'v',
type: 'boolean',
},
},
});
const {
extension,
verbose,
} = cli.flags;
if (!extension) {
console.error(chalk.bgRed('Missing --extension:') + ' You need to set the file extension to use for the output\n');
process.exit(1);
}
if (/[^\da-z]/.test(extension)) {
console.error(chalk.bgRed('Invalid --extension:') + ' Only lower case alpha numeric characters allowed in file extension\n');
process.exit(1);
}
if (cli.input.length === 0) {
console.error(chalk.bgRed('Missing files:') + ' You need to specify at least one file\n');
process.exit(1);
}
try {
await linemod(cli.input, { outputExtension: '.' + extension });
if (verbose) {
console.log(`Modifications applied successfully on ${chalk.bold(cli.input.length)} file(s)\n`);
}
} catch (err) {
console.error(
chalk.bgRed('Unexpected error:') +
(err instanceof Error ? ' ' + err.message + '\n\n' + err.stack : '') +
'\n'
);
process.exit(1);
}