@stampdwn/cli
v0.1.2
Published
Command-line interface for Stampdown
Maintainers
Readme
Stampdown CLI
Command-line interface for rendering and precompiling Stampdown templates.
The package installs the stampdown binary.
Installation
npm install -g @stampdwn/cliOverview
The CLI has two modes:
- Render mode is the default and processes one or more templates into Markdown output.
- Precompile mode is enabled with
--precompileand turns templates into optimized JavaScript bundles.
Render Mode
# Render a template with a JSON data file
stampdown -D data.json template.sdt
# Render with inline JSON data
stampdown -D '{"name":"World"}' template.sdt
# Register partials and helpers from globs
stampdown -P "partials/*.sdt" -H "helpers/*.js" -D data.json template.sdt
# Write rendered output into a directory with a custom extension
stampdown -D data.json -o dist -e html template.sdt
# Write rendered output to stdout
stampdown -D data.json -s template.sdt
# Read data from stdin
echo '{"name":"Alice"}' | stampdown -i template.sdtRender Options
-D, --data <glob|json>...Parse data from a file or inline JSON-P, --partial <glob>...Register partial templates from one or more globs-H, --helper <glob>...Register helper modules from one or more globs-o, --output <directory>Output directory for rendered files-e, --extension <ext>Output extension for generated files (default:md)-s, --stdoutOutput rendered content to stdout-i, --stdinRead JSON data from stdin--verboseEnable verbose logging
Precompile Mode
# Precompile all templates matched by a glob
stampdown --precompile --input "templates/**/*.sdt" -o dist
# Change output format
stampdown --precompile --input "templates/**/*.sdt" -o dist -f cjs
stampdown --precompile --input "templates/**/*.sdt" -o dist -f json
# Generate source maps
stampdown --precompile --input "templates/**/*.sdt" -o dist --source-map
# Restrict known helpers for tree-shaking
stampdown --precompile --input "templates/**/*.sdt" -k "if,each,with"
# Enable strict helper validation
stampdown --precompile --input "templates/**/*.sdt" --strictPrecompile Options
--precompileEnable precompile mode--input <glob>Input file or glob pattern-o, --output <dir>Output directory (default:./precompiled)-f, --format <format>Output format:esm,cjs, orjson(default:esm)-k, --known-helpers <list>Comma-separated list of known helpers orall--strictError on unknown helpers-w, --watchWatch matched files and rebuild on changes-m, --source-mapGenerate source maps--verboseEnable verbose logging
Helper Modules
Helper files can export a single function or named helper functions. Pass them with -H or --helper.
// helpers.js
module.exports = {
formatDate: (_context, _options, value) => new Date(value).toISOString().slice(0, 10),
repeat: (_context, _options, text, count = 2) => String(text).repeat(Number(count)),
};stampdown -H ./helpers.js -D data.json template.sdtOutput Files
- Render mode writes one output file per input template unless
--stdoutis used. - Precompile mode writes a single bundle file into the output directory:
templates.mjsforesmtemplates.cjsforcjstemplates.jsonforjson
API Docs
Full API reference: docs/index.md
Related Packages
@stampdwn/core- Core templating engine@stampdwn/llm- LLM prompt templating plugin@stampdwn/codemirror- CodeMirror language supportstampdown-language-support- VS Code extension
License
MIT
