-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·45 lines (37 loc) · 1022 Bytes
/
cli.js
File metadata and controls
executable file
·45 lines (37 loc) · 1022 Bytes
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
#!/usr/bin/env node
import process from 'node:process';
import fs from 'node:fs';
import getStdin from 'get-stdin';
import meow from 'meow';
import stripCssComments from 'strip-css-comments';
const cli = meow(`
Usage
$ strip-css-comments <input-file> > <output-file>
$ strip-css-comments < <input-string>
Options
--preserve=<regex> Preserve comments matching a regex [Default: ^!]
--no-preserve Strip all comments including \`/*!\`
Examples
$ strip-css-comments src/app.css > dist/app.css
$ strip-css-comments < src/app.css --preserve='^#'
`, {
importMeta: import.meta,
});
function init(data) {
console.log(stripCssComments(data, cli.flags));
}
const input = cli.input[0];
if (typeof cli.flags.preserve === 'string') {
cli.flags.preserve = new RegExp(cli.flags.preserve);
}
if (!input && process.stdin.isTTY) {
console.error('Specify a file path');
process.exit(1);
}
if (input) {
init(fs.readFileSync(input, 'utf8'));
} else {
(async () => {
init(await getStdin());
})();
}