Skip to content

Commit fc045b5

Browse files
committed
feat: CLI support
echo '{{ "hello" | capitalize }}' | liquidjs
1 parent c8c6dd8 commit fc045b5

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ engine
9898
.then(console.log) // outputs "Alice"
9999
```
100100

101+
Or from the CLI:
102+
103+
```bash
104+
echo '{{ "hello" | capitalize }}' | liquidjs
105+
```
106+
101107
## Use with Express.js
102108

103109
```javascript

bin/.eslintrc.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": ["standard"],
3+
"env": {
4+
"mocha": true,
5+
"es6": true,
6+
"browser": true,
7+
"node": true
8+
},
9+
"plugins": [
10+
"mocha",
11+
"standard",
12+
"promise"
13+
],
14+
"rules": {
15+
"no-var": 2,
16+
"prefer-const": 2,
17+
"@typescript-eslint/no-var-requires": "off",
18+
"no-unused-vars": "off",
19+
"indent": "off"
20+
}
21+
}

bin/liquid.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
3+
const Liquid = require('..')
4+
5+
let tpl = ''
6+
process.stdin.on('data', chunk => (tpl += chunk))
7+
process.stdin.on('end', () => render(tpl))
8+
9+
async function render (tpl) {
10+
const liquid = new Liquid()
11+
const html = await liquid.parseAndRender(tpl)
12+
console.log(html)
13+
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"build": "rollup -c rollup.config.ts && ls -lh dist",
1818
"version": "npm run build"
1919
},
20+
"bin": {
21+
"liquidjs": "./bin/liquid.js",
22+
"liquid": "./bin/liquid.js"
23+
},
2024
"repository": {
2125
"type": "git",
2226
"url": "git+https://github.com/harttle/liquidjs.git"

0 commit comments

Comments
 (0)