#!/usr/bin/env node const fs = require('fs/promises') const Liquid = require('..').Liquid render().catch(err => { process.stderr.write(`${err.message}\n`) process.exitCode = 1 }) async function render () { const { program } = require('commander') program .name('liquidjs') .description('Render a Liquid template') .argument('[template]', 'liquid template to render (inline, @path, or @- for stdin)') .option('-t, --template ', 'liquid template to render (inline, @path, or @- for stdin)') .option('-c, --context ', 'input context in JSON format (inline, @path, or @- for stdin)') .option('-o, --output ', 'write rendered output to file (omit to write to stdout)') .option('--cache [size]', 'cache previously parsed template structures (default cache size: 1024)') .option('--extname ', 'use a default filename extension when resolving partials and layouts') .option('--jekyll-include', 'use jekyll-style include (pass parameters to include variable of current scope)') .option('--js-truthy', 'use JavaScript-style truthiness') .option('--layouts ', 'directories from where to resolve layouts (defaults to --root)') .option('--lenient-if', 'do not throw on undefined variables in conditional expressions (when using --strict-variables)') .option('--no-dynamic-partials', 'always treat file paths for partials and layouts as a literal value') .option('--no-greedy', 'disable greedy matching for --trim* options') .option('--no-relative-reference', 'require absolute file paths for partials and layouts') .option('--ordered-filter-parameters', 'respect parameter order when using filters') .option('--output-delimiter-left ', 'left delimiter to use for liquid outputs') .option('--output-delimiter-right ', 'right delimiter to use for liquid outputs') .option('--partials ', 'directories from where to resolve partials (defaults to --root)') .option('--preserve-timezones', 'preserve input timezone in date filter') .option('--root ', 'directories from where to resolve partials and layouts (defaults to ".")') .option('--strict-filters', 'throw on undefined filters instead of skipping them') .option('--strict-variables', 'throw on undefined variables instead of rendering them as empty string') .option('--tag-delimiter-left', 'left delimiter to use for liquid tags') .option('--tag-delimiter-right', 'right delimiter to use for liquid tags') .option('--timezone-offset ', 'JavaScript timezone name or timezoneOffset value to use in date filter (defaults to local timezone)') .option('--trim-output-left', 'trim whitespace from left of liquid outputs') .option('--trim-output-right', 'trim whitespace from right of liquid outputs') .option('--trim-tag-left', 'trim whitespace from left of liquid tags') .option('--trim-tag-right', 'trim whitespace from right of liquid tags') .showHelpAfterError('Use -h or --help for additional information.') .parse() const options = program.opts() const positionalTemplate = 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