UNPKG

576 BJavaScriptView Raw
1#!/usr/bin/env node
2
3const Liquid = require('..').Liquid
4const contextArg = process.argv.slice(2)[0]
5let context = {}
6
7if (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
16let tpl = ''
17process.stdin.on('data', chunk => (tpl += chunk))
18process.stdin.on('end', () => render(tpl))
19
20async function render (tpl) {
21 const liquid = new Liquid()
22 const html = await liquid.parseAndRender(tpl, context)
23 process.stdout.write(html)
24}