Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elcharitas/cli-njk
CLI Utility for Nunjucks
https://github.com/elcharitas/cli-njk
cli nunjucks
Last synced: 1 day ago
JSON representation
CLI Utility for Nunjucks
- Host: GitHub
- URL: https://github.com/elcharitas/cli-njk
- Owner: elcharitas
- License: mit
- Created: 2020-12-08T03:19:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-29T21:08:36.000Z (almost 4 years ago)
- Last Synced: 2024-12-15T07:35:32.967Z (8 days ago)
- Topics: cli, nunjucks
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CLI Nunjucks
> A Simple Nunjucks CLI Wrapper and templates watcher with Extension support, to generate precompiled template files or static HTML files.
## Installation
```bash
# Using NPM?
npm i -g cli-njk# Using Yarn?
yarn add cli-njk
```## Usage
```bash
$ njk [options]
```_Just like [Nunjucks CLI][], the `process.env` object is added to the context as `env`._
#### Basic examples
```bash
$ njk foo.njk --options njk.json
```Compiles `foo.njk` to `foo.html` with options from `njk.json` (and variables from `process.env` as `env`).
```bash
$ njk **/*.njk
```Compiles all `.njk` files (including subdirectories), except the ones starting by `_` (so you can use them as layouts).
## CLI Options
**--help, -h, -?**
Setting this option will Display or Show the help
``` bash
$ njk --help
```**--version**
Setting this option will Show the current version number
``` bash
$ njk -v
# 1.0.0
```**--path, -p**
This sets the path where templates live. Defaults to the path in `process.cwd()`
``` bash
$ njk *.njk -p src
```
See**--outDir, --out, -D**
The path to output compiled templates
``` bash
$ njk *.njk -D dist
```**--outFile**
The path to file for precompiled templates. When set, all discovered templates will be bundled into the file
``` bash
$ njk *.njk --outFile precompiled.js
```
See**--watch, -w**
Watch files change, except files starting by "_"
**N/B**: Template watching is only allowed for rendering and as such the `--render` flag must be used
``` bash
$ njk *.njk --watch --render
```**--render, -r**
Whether or not to render files or precompile them. When not set, templates are precompiled and bundled if `--outFile` flag is used
``` bash
$ njk *.njk --render
# Renders static HTML
```**--extension, -e**
Extension of the rendered or precompiled files
``` bash
# When rendering
$ njk *.njk -r -e html# When precompiling...
$ njk *.njk -e js
```**--extensions, -E**
Set of Extensions to use. The extensions are included using nodejs' `require()`.
To use [Nunjucks Reactive](https://github.com/nunjucks-reactive) for instance, we can write something like this
``` bash
$ njk *.njk -E nunjucks-reactive
```
Files in the `--path` specified can also be included using their relative paths.
``` bash
$ njk *.njk -E ./wrapfile ../extender
```
See**--options, -O**
Setting up an options file can come quite handy. cli nunjucks currently supports two major scopes in options
- Nunjucks options found in `config`
``` json
{
"config": {
"trimBlocks": true,
"lstripBlocks": true,
"noCache": true
}
}
```
See
- Nunjucks Compiler options
* Environment context
``` json
{
"compiler": {
"context": {
"package": "cli-njk"
}
}
```
* Array of extensions to load. Similar to using the `-E` flag
``` json
{
"compiler": {
"extensions": [
"./extended",
"nunjucks-reactive"
]
}
}
```
- Nunjucks CLI optionsSome other cli options are supported provided its not their alias.
``` json
{
"compiler": {
"outDir": "dist"
}
}
```See
### Advanced examples
```bash
$ njk foo.njk -p src -o dist -O njk.json
```Compiles `src/foo.njk` to `dist/foo.html`, with `njk.json` as njk environment options.
```bash
$ njk *.njk njk.json -w -r -p src
```Compiles and renders all `.njk` files -- except ones starting with `_` -- in the `src` folder to the current working directory, with `njk.json` as metadata, and keeps running in the background for files changes.
[Nunjucks CLI]: http://github.com/jeremyben/nunjucks-cli