-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathcli.js
More file actions
63 lines (51 loc) · 1.39 KB
/
cli.js
File metadata and controls
63 lines (51 loc) · 1.39 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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);
});
}