-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
executable file
·36 lines (30 loc) · 848 Bytes
/
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
import process from 'node:process';
import fs from 'node:fs';
import getStdin from 'get-stdin';
import meow from 'meow';
import stripJsonComments from 'strip-json-comments';
const cli = meow(`
Usage
$ strip-json-comments <input-file> > <output-file>
$ strip-json-comments < <input-string>
Options
--no-whitespace Remove comments instead of replacing them with whitespace
Example
$ strip-json-comments input.json > output.json
`, {
importMeta: import.meta,
flags: {
whitespace: {
type: 'boolean',
default: true,
},
},
});
const input = cli.input[0];
if (!input && process.stdin.isTTY) {
console.error('Specify a file path');
process.exit(1);
}
const data = input ? fs.readFileSync(input, 'utf8') : await getStdin();
console.log(stripJsonComments(data, {...cli.flags, trailingCommas: true}));