forked from kristian/minify-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
40 lines (31 loc) · 691 Bytes
/
cli.js
File metadata and controls
40 lines (31 loc) · 691 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
#!/usr/bin/env node
const fs = require("fs");
const meow = require("meow");
const minify = require("./").minify;
const cli = meow(`
Usage
$ minify-xml <input>
Options
--in-place, -i Save the minified results to the original file
Examples
$ minify-xml --in-place sitemap.xml
`, {
flags: {
inPlace: {
type: "boolean",
alias: "i",
},
},
});
const file = cli.input[0];
if (!file) {
cli.showHelp(); // this exits the process.
}
const xml = fs.readFileSync(file, "utf8").toString();
const minified = minify(xml).trimEnd();
if (cli.flags.inPlace) {
console.log(`Writing to ${file}`);
fs.writeFileSync(file, minified);
} else {
process.stdout.write(minified);
}