Skip to content

Commit

Permalink
Merge pull request #19 from simonewebdesign/main
Browse files Browse the repository at this point in the history
Add CLI
  • Loading branch information
tigt authored May 8, 2021
2 parents e3f87d2 + 8034aaf commit 0edcc72
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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(out) : console.log(out);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Small, efficient encoding of SVG data URIs for CSS, HTML, etc.",
"main": "index.js",
"types": "index.d.ts",
"bin": "cli.js",
"repository": {
"type": "git",
"url": "git+https://github.com/tigt/mini-svg-data-uri.git"
Expand Down

0 comments on commit 0edcc72

Please sign in to comment.