Skip to content

Commit

Permalink
Add CLI script
Browse files Browse the repository at this point in the history
  • Loading branch information
jamen committed Apr 4, 2018
1 parent e850635 commit cfd03e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
27 changes: 27 additions & 0 deletions bin/pixie-cli.js
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"uglify-js": "^3.3.18"
},
"dependencies": {
"@jamen/bench": "^0.2.0"
"@jamen/bench": "^0.2.0",
"minimist": "^1.2.0"
}
}
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 &copy; [Jamen Marz](http://jamenmarz.com/)
Expand Down

0 comments on commit cfd03e4

Please sign in to comment.