forked from jonkemp/inline-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fkoyer/cli
Add Command Line Interface
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters