From fc045b5bbc45bf68ce53a725871cff8045351420 Mon Sep 17 00:00:00 2001 From: harttle Date: Thu, 1 Aug 2019 13:15:23 +0800 Subject: [PATCH] feat: CLI support echo '{{ "hello" | capitalize }}' | liquidjs --- README.md | 6 ++++++ bin/.eslintrc.json | 21 +++++++++++++++++++++ bin/liquid.js | 13 +++++++++++++ package.json | 4 ++++ 4 files changed, 44 insertions(+) create mode 100644 bin/.eslintrc.json create mode 100755 bin/liquid.js diff --git a/README.md b/README.md index 361e7c4953..d25a93a502 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,12 @@ engine .then(console.log) // outputs "Alice" ``` +Or from the CLI: + +```bash +echo '{{ "hello" | capitalize }}' | liquidjs +``` + ## Use with Express.js ```javascript diff --git a/bin/.eslintrc.json b/bin/.eslintrc.json new file mode 100644 index 0000000000..9521b35897 --- /dev/null +++ b/bin/.eslintrc.json @@ -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" + } +} diff --git a/bin/liquid.js b/bin/liquid.js new file mode 100755 index 0000000000..358b2c2476 --- /dev/null +++ b/bin/liquid.js @@ -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) +} \ No newline at end of file diff --git a/package.json b/package.json index bafee2d881..7cb92984ee 100644 --- a/package.json +++ b/package.json @@ -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"