diff --git a/bin/pixie-cli.js b/bin/pixie-cli.js new file mode 100755 index 0000000..aafca86 --- /dev/null +++ b/bin/pixie-cli.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node + +var pixie = require('../dist/pixie.js') +var minimist = require('minimist') + +if (process.stdin.isTTY) { + console.error('Pixie cannot be used without stdio.') + process.exit(1) +} + +var chunks = [] +process.stdin.on('data', function (buf) { + chunks.push(buf) +}) + +process.stdin.on('end', function () { + var source = Buffer.concat(chunks) + main(source) +}) + +function main (source) { + var data = minimist(process.argv.slice(2)) + var tags = process.env.PIXIE_TAGS + tags = tags ? tags.split(',') : ['{{', '}}'] + var output = pixie.render(source.toString(), data, tags[0], tags[1]) + return process.stdout.write(output) +} diff --git a/package-lock.json b/package-lock.json index 1e54d8d..2683b6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -545,8 +545,7 @@ "minimist": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "mutexify": { "version": "1.2.0", diff --git a/package.json b/package.json index f182f80..191d3e4 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "uglify-js": "^3.3.18" }, "dependencies": { - "@jamen/bench": "^0.2.0" + "@jamen/bench": "^0.2.0", + "minimist": "^1.2.0" } } diff --git a/readme.md b/readme.md index d23b134..f254036 100644 --- a/readme.md +++ b/readme.md @@ -60,6 +60,14 @@ An array containing two other arrays recognized as `[fragments, expressions]`. - **Expressions**: Data between opening and closing tags. In `Foo {{bar}} baz {{qux}}` it would be `['bar', 'qux']`. - **Fragments**: Data around your expressions. In the same example, the fragments would be `['Foo ', ' baz', '']`. +### Command-line Interface + +The package also includes a CLI. It just parses stdin and compiles stdout. + +```sh +pixie --name "John Doe" < template.src.md > template.md +``` + ## License MIT © [Jamen Marz](http://jamenmarz.com/)