diff --git a/README.md b/README.md index 1166db9..8532c3f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Options: With no FILE, or when FILE is -, read standard input. ``` + ## Documentation See https://github.com/jonkemp/inline-css/ diff --git a/bin/cli.js b/bin/cli.js new file mode 100644 index 0000000..0713034 --- /dev/null +++ b/bin/cli.js @@ -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); + }); +} + diff --git a/package.json b/package.json index c81435b..e998f7f 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,9 @@ "index.js", "lib/" ], + "bin": { + "inline-css": "bin/cli.js" + }, "repository": "jonkemp/inline-css", "keywords": [ "inline",