feat: CLI support

echo '{{ "hello" | capitalize }}' | liquidjs
This commit is contained in:
harttle
2019-08-01 13:15:55 +08:00
parent c8c6dd8275
commit fc045b5bbc
4 changed files with 44 additions and 0 deletions
+6
View File
@@ -98,6 +98,12 @@ engine
.then(console.log) // outputs "Alice"
```
Or from the CLI:
```bash
echo '{{ "hello" | capitalize }}' | liquidjs
```
## Use with Express.js
```javascript
+21
View File
@@ -0,0 +1,21 @@
{
"extends": ["standard"],
"env": {
"mocha": true,
"es6": true,
"browser": true,
"node": true
},
"plugins": [
"mocha",
"standard",
"promise"
],
"rules": {
"no-var": 2,
"prefer-const": 2,
"@typescript-eslint/no-var-requires": "off",
"no-unused-vars": "off",
"indent": "off"
}
}
Executable
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env node
const Liquid = require('..')
let tpl = ''
process.stdin.on('data', chunk => (tpl += chunk))
process.stdin.on('end', () => render(tpl))
async function render (tpl) {
const liquid = new Liquid()
const html = await liquid.parseAndRender(tpl)
console.log(html)
}
+4
View File
@@ -17,6 +17,10 @@
"build": "rollup -c rollup.config.ts && ls -lh dist",
"version": "npm run build"
},
"bin": {
"liquidjs": "./bin/liquid.js",
"liquid": "./bin/liquid.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/harttle/liquidjs.git"