Simple CLI static site builder tool with Twig.
- Lightweight CLI for generating static sites.
- Uses Twig.js templating engine for simplified markup.
- Has integrated custom Twig extensions (e.g., translations, sorting)
- Minifies output HTML.
- Simple integration with Gulp and other build tools via CLI.
- Configured via custom JSON configuration, allowing for extensive customization of build settings.
- Zero dependencies on complex frameworks.
Install Tateru CLI locally in your project:
npm i -D tateru-cliOr install globally:
npm i -g tateru-cli- Create a config file
tateru.config.jsonwith your settings (see example in./example/tateru.config.json). - Run the CLI command:
npx tateru-cli tateru.config.jsonOr, if installed globally:
tateru-cli tateru.config.jsontateru-cli tateru.config.json --env prodThis generates the site with the prod environment settings.
To display usage details, run:
tateru-cli --helpor
npx tateru-cli --help(Experimental) Integration with Gulp
You can use Tateru CLI within a Gulp task by executing it via child_process.exec:
/** @file tasks/tateru.js */
const { exec } = require('child_process');
module.exports = function tateru(cb) {
return new Promise((resolve) => {
exec('npx tateru-cli tateru.config.json', function (error, stdout, stderr) {
if (error && stdout) {
console.error(stdout);
} else if (stdout) {
console.info(stdout);
}
if (stderr) {
console.error(stderr);
}
resolve(cb);
})
})
}/** @file gulpfile.js */
const { series, parallel } = require('gulp');
const tateru = require('./tasks/tateru');
function build(cb) {
return series(clean, parallel(css, tateru))(cb);
}
module.exports = {
build,
default: build,
};The tateru.config.json file defines how Tateru CLI generates your static site. Below is a breakdown of the configuration structure:
"env": {
"dev": {
"data": {
"app": {
"environment": "dev"
}
}
},
"prod": {
"data": {
"app": {
"environment": "prod"
}
}
}
}Defines environment-specific variables (dev, prod).
data: Overrides specific data inoptions.data, allowing for environment-based customization.
"options": {
"data": {
"app": {
"environment": "dev",
"root": "/"
},
"title": "Tateru CLI Example",
"domain": "https://www.example.com/"
},
"src": "src/twig",
"ext": "dist"
}data: Global variables accessible in templates. For example, you can referencetitlein a Twig template using{{- title -}}.src: Path to source Twig files.ext: Output directory for compiled files.
The final data available in Twig templates is composed by merging several configuration sources:
options.data: Global data defined in thetateru.config.jsonfile.env.[env].data: Environment-specific data (devorprod).pages.[lang].[page].data: Page-specific overrides.href: Automatically generated URLs for each page.lang: The current language in use.
Example of referencing global data in a Twig template:
<h1>{{ title }}</h1>
<p>Environment: {{ app.environment }}</p>
<a href="{{ href.index }}">Home</a>"translations": {
"cs": {
"src": "src/translations/cs.json",
"ext": ""
}
}Defines translation files per language.
"pages": {
"cs": {
"index": {
"data": {
"page": "index",
"title": "Index Page"
},
"src": "views/index.html.twig",
"ext": "index.html",
"minify": ["prod", "dev"]
}
}
}pages: Defines each page with its template source, output name, and optional minification settings.data: Page-specific variables that override global data inoptions.data.src: Path to the Twig template file for this page.ext: Output file name and extension.minify: Array specifying environments (prod,dev) where HTML minification should be applied.
For more complex configurations, refer to /example/tateru.config.json.
{{ trans('homepage.title') }}Example translation.json:
{
"sort": [
{ "key": "x" },
{ "key": "a" },
{ "key": "k" },
{ "key": "c" },
{ "key": "b" }
]
}Example index.html.twig:
<ul>
{% for item in trans('sort')|sort_by('key') -%}
<li>{{ item.key }}</li>
{% endfor %}
</ul>To build the project:
npm run buildTo clean the output directory:
npm run cleanTo run an example build:
npm run example:buildTo run an example production build:
npm run example:build:prodTo clean example output:
npm run example:cleanTo run the CLI in development mode:
npm run devTest CLI help:
npm run dev:helpTest CLI version:
npm run dev:versionTest CLI with arguments:
npm run dev:argsTest CLI error:
npm run dev:errorTest CLI arguments error:
npm run dev:args-errorTest CLI argument with missing value error:
npm run dev:missing-arg-errorRun unit tests:
npm testWant to contribute? Feel free to open an issue or pull request on GitHub! π
- Fork the repo
- Create a new branch (
git checkout -b feature-branch) - Make your changes
- Commit the changes (
git commit -m "Add new feature") - Push to the branch (
git push origin feature-branch) - Open a pull request π
MIT License Β© 2025 Daniel Sitek