Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI #19

Merged
merged 1 commit into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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