mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 09:05:14 -07:00
feat!: remove --template CLI option
Template is positional-only; bare stdin template and --template/-t are both removed. Keep @- for template and --context. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -47,7 +47,6 @@ npm install liquidjs
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx liquidjs 'Hello, {{ name }}!' --context '{"name": "Liquid"}'
|
npx liquidjs 'Hello, {{ name }}!' --context '{"name": "Liquid"}'
|
||||||
# or: npx liquidjs --template 'Hello, {{ name }}!' --context '{"name": "Liquid"}'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [setup guide][setup] for partials, layouts, caching, and other options.
|
See the [setup guide][setup] for partials, layouts, caching, and other options.
|
||||||
|
|||||||
+2
-13
@@ -14,8 +14,7 @@ async function render () {
|
|||||||
program
|
program
|
||||||
.name('liquidjs')
|
.name('liquidjs')
|
||||||
.description('Render a Liquid template')
|
.description('Render a Liquid template')
|
||||||
.argument('[template]', 'liquid template to render (inline, @path, or @- for stdin)')
|
.argument('<template>', 'liquid template to render (inline, @path, or @- for stdin)')
|
||||||
.option('-t, --template <liquid | @path>', 'liquid template to render (inline, @path, or @- for stdin)')
|
|
||||||
.option('-c, --context <json | @path>', 'input context in JSON format (inline, @path, or @- for stdin)')
|
.option('-c, --context <json | @path>', 'input context in JSON format (inline, @path, or @- for stdin)')
|
||||||
.option('-o, --output <path>', 'write rendered output to file (omit to write to stdout)')
|
.option('-o, --output <path>', 'write rendered output to file (omit to write to stdout)')
|
||||||
.option('--cache [size]', 'cache previously parsed template structures (default cache size: 1024)')
|
.option('--cache [size]', 'cache previously parsed template structures (default cache size: 1024)')
|
||||||
@@ -46,17 +45,7 @@ async function render () {
|
|||||||
.parse()
|
.parse()
|
||||||
|
|
||||||
const options = program.opts()
|
const options = program.opts()
|
||||||
const positionalTemplate = program.args[0]
|
const templateOption = program.args[0]
|
||||||
const optionTemplate = options.template
|
|
||||||
|
|
||||||
if (positionalTemplate && optionTemplate && positionalTemplate !== optionTemplate) {
|
|
||||||
throw new Error(`Conflicting templates: positional argument and --template differ.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const templateOption = positionalTemplate || optionTemplate
|
|
||||||
if (!templateOption) {
|
|
||||||
throw new Error(`A template is required. Pass a positional <template> or --template.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.values({ template: templateOption, context: options.context }).filter((value) => value === '@-').length > 1) {
|
if (Object.values({ template: templateOption, context: options.context }).filter((value) => value === '@-').length > 1) {
|
||||||
throw new Error(`The stdin input specifier '@-' must only be used once.`)
|
throw new Error(`The stdin input specifier '@-' must only be used once.`)
|
||||||
|
|||||||
@@ -53,11 +53,10 @@ Pre-built UMD bundles are also available:
|
|||||||
|
|
||||||
## LiquidJS in CLI
|
## LiquidJS in CLI
|
||||||
|
|
||||||
LiquidJS can also be used to render a template directly from CLI using `npx`. Pass the template as a positional argument, or with `--template` / `-t`:
|
LiquidJS can also be used to render a template directly from CLI using `npx`. Pass the template as a positional argument:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx liquidjs '{{"hello" | capitalize}}'
|
npx liquidjs '{{"hello" | capitalize}}'
|
||||||
npx liquidjs --template '{{"hello" | capitalize}}'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
You can either pass the template inline (as shown above), read it from a file with `@` followed by a path, or from `stdin` with `@-`:
|
You can either pass the template inline (as shown above), read it from a file with `@` followed by a path, or from `stdin` with `@-`:
|
||||||
|
|||||||
Reference in New Issue
Block a user