1 | #!/usr/bin/env node
|
2 |
|
3 | const Liquid = require('..').Liquid
|
4 | const contextArg = process.argv.slice(2)[0]
|
5 | let context = {}
|
6 |
|
7 | if (contextArg) {
|
8 | if (contextArg.endsWith('.json')) {
|
9 | const fs = require('fs')
|
10 | context = JSON.parse(fs.readFileSync(contextArg, 'utf8'))
|
11 | } else {
|
12 | context = JSON.parse(contextArg)
|
13 | }
|
14 | }
|
15 |
|
16 | let tpl = ''
|
17 | process.stdin.on('data', chunk => (tpl += chunk))
|
18 | process.stdin.on('end', () => render(tpl))
|
19 |
|
20 | async function render (tpl) {
|
21 | const liquid = new Liquid()
|
22 | const html = await liquid.parseAndRender(tpl, context)
|
23 | process.stdout.write(html)
|
24 | }
|