Skip to content

Commit

Permalink
Merge pull request #1 from fkoyer/cli
Browse files Browse the repository at this point in the history
Add Command Line Interface
  • Loading branch information
fkoyer authored Jan 7, 2021
2 parents 24bcb9d + 3d7bd00 commit cd3d622
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Options:

With no FILE, or when FILE is -, read standard input.
```

## Documentation

See https://github.com/jonkemp/inline-css/
Expand Down
63 changes: 63 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node

"use strict";

var fs = require("fs");
var path = require("path");
var pkg = require("../package.json");
var inlineCss = require('../');

var binname = Object.keys(pkg.bin)[0];

var options = {};
var html = process.argv[2];

switch (html) {
case "--version":
case "-v":
console.log(binname + " v" + pkg.version);

break;

case "--help":
case "-h":
console.log("Usage: " + binname + " [FILE]");
console.log("");
console.log("Description:");
console.log(" " + pkg.description);
console.log("");
console.log("Options:");
console.log(" -h, --help Show this message.");
console.log(" -v, --version Print version information.");
console.log("");
console.log("With no FILE, or when FILE is -, read standard input.");

break;

case "-":
case undefined:
options.url = 'file://' + process.cwd() + '/';
var stdin = process.openStdin();
html = "";
stdin.setEncoding("utf-8");
stdin.on("data", function (chunk) {
html += chunk;
});
stdin.on("end", function () {
inlineCss(html, options)
.then(function(html) {
console.log(html);
});
});

break;

default:
options.url = 'file://' + path.dirname(path.resolve(html)) + '/';
html = fs.readFileSync(html, "utf8");
inlineCss(html, options)
.then(function(html) {
console.log(html);
});
}

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
"index.js",
"lib/"
],
"bin": {
"inline-css": "bin/cli.js"
},
"repository": "jonkemp/inline-css",
"keywords": [
"inline",
Expand Down

0 comments on commit cd3d622

Please sign in to comment.