-
Notifications
You must be signed in to change notification settings - Fork 16
/
cli.js
executable file
·41 lines (33 loc) · 850 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
37
38
39
40
41
#!/usr/bin/env node
let help = `
Usage: mini-svg-data-uri <source> [dest]
Options:
-v, --version Output the version number
-h, --help Display help for command
Examples:
mini-svg-data-uri file.svg Write to stdout
mini-svg-data-uri icon.svg icon.uri Write to file
`;
let [source, dest] = process.argv.slice(2);
switch (source) {
case '-h':
case '--help':
case undefined:
console.log(help);
process.exit();
case '-v':
case '--version':
console.log(require('./package').version);
process.exit();
}
const fs = require('fs');
const svgToMiniDataURI = require('.');
fs.readFile(source, 'utf8', (err, data) => {
if (err) {
console.error(err.message);
console.log(help);
process.exit(1);
}
const out = svgToMiniDataURI(data);
dest ? fs.writeFileSync(dest, out) : console.log(out);
});