Skip to content

Commit cd3d622

Browse files
authored
Merge pull request #1 from fkoyer/cli
Add Command Line Interface
2 parents 24bcb9d + 3d7bd00 commit cd3d622

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Options:
2323

2424
With no FILE, or when FILE is -, read standard input.
2525
```
26+
2627
## Documentation
2728

2829
See https://github.com/jonkemp/inline-css/

bin/cli.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
5+
var fs = require("fs");
6+
var path = require("path");
7+
var pkg = require("../package.json");
8+
var inlineCss = require('../');
9+
10+
var binname = Object.keys(pkg.bin)[0];
11+
12+
var options = {};
13+
var html = process.argv[2];
14+
15+
switch (html) {
16+
case "--version":
17+
case "-v":
18+
console.log(binname + " v" + pkg.version);
19+
20+
break;
21+
22+
case "--help":
23+
case "-h":
24+
console.log("Usage: " + binname + " [FILE]");
25+
console.log("");
26+
console.log("Description:");
27+
console.log(" " + pkg.description);
28+
console.log("");
29+
console.log("Options:");
30+
console.log(" -h, --help Show this message.");
31+
console.log(" -v, --version Print version information.");
32+
console.log("");
33+
console.log("With no FILE, or when FILE is -, read standard input.");
34+
35+
break;
36+
37+
case "-":
38+
case undefined:
39+
options.url = 'file://' + process.cwd() + '/';
40+
var stdin = process.openStdin();
41+
html = "";
42+
stdin.setEncoding("utf-8");
43+
stdin.on("data", function (chunk) {
44+
html += chunk;
45+
});
46+
stdin.on("end", function () {
47+
inlineCss(html, options)
48+
.then(function(html) {
49+
console.log(html);
50+
});
51+
});
52+
53+
break;
54+
55+
default:
56+
options.url = 'file://' + path.dirname(path.resolve(html)) + '/';
57+
html = fs.readFileSync(html, "utf8");
58+
inlineCss(html, options)
59+
.then(function(html) {
60+
console.log(html);
61+
});
62+
}
63+

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
"index.js",
3838
"lib/"
3939
],
40+
"bin": {
41+
"inline-css": "bin/cli.js"
42+
},
4043
"repository": "jonkemp/inline-css",
4144
"keywords": [
4245
"inline",

0 commit comments

Comments
 (0)