Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ inlineCss(html, options)
.then(function(html) { console.log(html); });
```

## CLI
```console
$ inline-css -h
Usage: inline-css [FILE]

Description:
Inline css into an html file.

Options:
-h, --help Show this message.
-v, --version Print version information.

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

## API

### inlineCss(html, options)
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