mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
feat!: require positional template; drop bare stdin and --template (#942)
* feat!: remove CLI support for template via STDIN Fixes #940 Co-authored-by: Cursor <[email protected]> * feat!: take CLI template as positional argument Make template a required positional arg (drop --template) for v11 per #586; stdin template remains unsupported without a special error. Co-authored-by: Cursor <[email protected]> * fix: restore --template CLI option Revert the positional-only template change. Keep --template as the primary API; stdin template remains unsupported without a special error. Co-authored-by: Cursor <[email protected]> * fix: restore explicit @- stdin for template and context Keep @- for --template and --context; only the legacy bare-stdin-as-template fallback stays removed. Co-authored-by: Cursor <[email protected]> * feat: accept CLI template as positional or --template Support positional <template> alongside --template/-t for compatibility; error if both are set and differ. Bare stdin template remains removed; @- still works. Co-authored-by: Cursor <[email protected]> * 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]> --------- Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -53,44 +53,39 @@ Pre-built UMD bundles are also available:
|
||||
|
||||
## LiquidJS in CLI
|
||||
|
||||
LiquidJS can also be used to render a template directly from CLI using `npx`:
|
||||
LiquidJS can also be used to render a template directly from CLI using `npx`. Pass the template as a positional argument:
|
||||
|
||||
```bash
|
||||
npx liquidjs --template '{{"hello" | capitalize}}'
|
||||
npx liquidjs '{{"hello" | capitalize}}'
|
||||
```
|
||||
|
||||
You can either pass the template inline (as shown above) or you can read it from a file by using the `@` character followed by a path, like so:
|
||||
You can either pass the template inline (as shown above), read it from a file with `@` followed by a path, or from `stdin` with `@-`:
|
||||
|
||||
```bash
|
||||
npx liquidjs --template @./some-template.liquid
|
||||
npx liquidjs @./some-template.liquid
|
||||
echo '{{"hello" | capitalize}}' | npx liquidjs @-
|
||||
```
|
||||
|
||||
You can also use the `@-` syntax to read the template from `stdin`:
|
||||
A context can be passed the same ways (inline, from a path, or via `@-` for `stdin`). The following three are equivalent:
|
||||
|
||||
```bash
|
||||
echo '{{"hello" | capitalize}}' | npx liquidjs --template @-
|
||||
npx liquidjs 'Hello, {{ name }}!' --context '{"name": "Snake"}'
|
||||
npx liquidjs 'Hello, {{ name }}!' --context @./some-context.json
|
||||
echo '{"name": "Snake"}' | npx liquidjs 'Hello, {{ name }}!' --context @-
|
||||
```
|
||||
|
||||
A context can be passed in the same ways (i.e. inline, from a path or piped through `stdin`). The following three are equivalent:
|
||||
|
||||
```bash
|
||||
npx liquidjs --template 'Hello, {{ name }}!' --context '{"name": "Snake"}'
|
||||
npx liquidjs --template 'Hello, {{ name }}!' --context @./some-context.json
|
||||
echo '{"name": "Snake"}' | npx liquidjs --template 'Hello, {{ name }}!' --context @-
|
||||
```
|
||||
|
||||
Note that you can only use the `stdin` specifier `@-` for a single argument. If you try to use it for both `--template` and `--context` you will get an error.
|
||||
Note that you can only use the `stdin` specifier `@-` for a single argument. If you try to use it for both the template and `--context` you will get an error.
|
||||
|
||||
The rendered output is written to `stdout` by default, but you can also specify an output file (if the file exists, it will be overwritten):
|
||||
|
||||
```bash
|
||||
npx liquidjs --template '{{"hello" | capitalize}}' --output ./hello.txt
|
||||
npx liquidjs '{{"hello" | capitalize}}' --output ./hello.txt
|
||||
```
|
||||
|
||||
You can also pass a number of options to customize template rendering behavior. For example, the `--js-truthy` option can be used to enable JavaScript truthiness:
|
||||
|
||||
```bash
|
||||
npx liquidjs --template @./some-template.liquid --js-truthy
|
||||
npx liquidjs @./some-template.liquid --js-truthy
|
||||
```
|
||||
|
||||
Most of the [options available through the JavaScript API][options] are also available from the CLI. For help on available options, use `npx liquidjs --help`.
|
||||
|
||||
Reference in New Issue
Block a user