@rse/nunjucks-cli 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,22 +14,35 @@ This is a small command-line utility to render templates with the rich
14
14
  and powerful templating language [Mozilla Nunjucks](https://mozilla.github.io/nunjucks/).
15
15
  This allows you to define your configuration in a YAML file and then render
16
16
  an output file based on a template input file where your configuration can be expanded.
17
+ It optionally can load Nunjucks addons like the ones from the companion
18
+ [Nunjucks Addons](https://github.com/rse/nunjucks-addons) package.
17
19
 
18
- Installation
19
- ------------
20
+ Installation & Usage
21
+ --------------------
20
22
 
21
23
  ```sh
24
+ # plain functionality
22
25
  $ npm install -g @rse/nunjucks-cli
26
+ $ nunjucks [...]
27
+
28
+ # with addon functionality
29
+ $ npm install -g @rse/nunjucks-cli @rse/nunjucks-addons
30
+ $ nunjucks -e @rse/nunjucks-addons [...]
23
31
  ```
24
32
 
25
- Alternatively, instead of globally installing it, let it be automatically installed on-the-fly:
33
+ Alternatively, instead of globally installing it, you can also use it on-the-fly:
26
34
 
27
35
  ```sh
28
- $ npx @rse/nunjucks-cli [...]
36
+ # plain functionality
37
+ $ npx --yes @rse/nunjucks-cli [...]
38
+
39
+ # with addon functionality
40
+ $ npx --yes --package @rse/nunjucks-cli --package @rse/nunjucks-addons -- \
41
+ nunjucks -e @rse/nunjucks-addons [...]
29
42
  ```
30
43
 
31
- Usage
32
- -----
44
+ Options
45
+ -------
33
46
 
34
47
  ```
35
48
  $ nunjucks
@@ -52,8 +65,8 @@ $ nunjucks
52
65
  load context definition YAML file.
53
66
  - `-D`|`--define` `<key>=<value>`:<br/>
54
67
  set context definition key/value.
55
- - `-e`|`--extension` `default|date|eval|jsonpath|pad|sprintf|uuid|<module-name>`:<br/>
56
- load Nunjucks JavaScript extension module (built-in or NPM installed).
68
+ - `-e`|`--extension` `<module-name>`:<br/>
69
+ load Nunjucks JavaScript extension module (installed via NPM).
57
70
  - `-o`|`--output` `<output-file>`|`-`:<br/>
58
71
  save output file (or stdout).
59
72
  - `<input-file>`|`-`:<br/>
package/nunjucks.js CHANGED
@@ -139,8 +139,6 @@ const env = nunjucks.configure(inputFile, options)
139
139
  /* load external extension files */
140
140
  if (typeof argv.extension === "object" && argv.extension instanceof Array) {
141
141
  for (let extension of argv.extension) {
142
- if (extension.match(/^(?:default|date|eval|jsonpath|pad|sprintf|uuid)$/))
143
- extension = path.join(__dirname, "nunjucks.d", `${extension}.js`)
144
142
  let modpath = null
145
143
  try {
146
144
  modpath = require.resolve(extension)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rse/nunjucks-cli",
3
3
  "publishConfig": { "access": "public" },
4
- "version": "1.2.1",
4
+ "version": "1.3.0",
5
5
  "description": "Nunjucks Template Rendering Command-Line Interface",
6
6
  "author": {
7
7
  "name": "Dr. Ralf S. Engelschall",
@@ -9,6 +9,13 @@
9
9
  "url": "http://engelschall.com"
10
10
  },
11
11
  "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git://github.com/rse/nunjucks-cli.git"
15
+ },
16
+ "bugs": {
17
+ "url": "http://github.com/rse/nunjucks-cli/issues"
18
+ },
12
19
  "bin": {
13
20
  "nunjucks": "nunjucks.js"
14
21
  },
@@ -16,11 +23,6 @@
16
23
  "nunjucks": "3.2.4",
17
24
  "chalk": "4.1.0",
18
25
  "yargs": "17.7.2",
19
- "moment": "2.29.4",
20
- "moment-timezone": "0.5.43",
21
- "jsonpath": "1.1.1",
22
- "sprintfjs": "1.2.17",
23
- "pure-uuid": "1.7.0",
24
26
  "js-yaml": "4.1.0"
25
27
  },
26
28
  "devDependencies": {
@@ -1,38 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- const moment = require("moment")
8
- const nlib = require("nunjucks/src/lib")
9
-
10
- module.exports = (env) => {
11
- /* add a "date" formatting filter */
12
- env.addFilter("date", (date, format, ...args) => {
13
- let result
14
- const errs = []
15
- let obj
16
- try {
17
- obj = moment(date)
18
- }
19
- catch (err) {
20
- errs.push(err)
21
- }
22
- if (obj) {
23
- try {
24
- if (obj[format] && nlib.isFunction(obj[format]))
25
- result = obj[format](obj, ...args.slice(2))
26
- else
27
- result = obj.format(format)
28
- }
29
- catch (err) {
30
- errs.push(err)
31
- }
32
- }
33
- if (errs.length)
34
- return errs.join("\n")
35
- return result
36
- })
37
- }
38
-
@@ -1,52 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- module.exports = (env) => {
8
- const globals = {
9
- bool: (val) => {
10
- if (typeof val === "undefined") return false
11
- else if (typeof val === "boolean") return val
12
- else if (typeof val === "number") return !isNaN(val) && val !== 0
13
- else if (typeof val === "string") return val.match(/^(?:true|yes)$/i) !== null
14
- else return !!val
15
- },
16
- int: (val) => {
17
- if (typeof val === "undefined") return NaN
18
- else if (typeof val === "boolean") return val ? 1 : 0
19
- else if (typeof val === "number") return val
20
- else if (typeof val === "string") return parseInt(val, 10)
21
- else return 0
22
- },
23
- float: (val) => {
24
- if (typeof val === "undefined") return NaN
25
- else if (typeof val === "boolean") return val ? 1.0 : 0.0
26
- else if (typeof val === "number") return val
27
- else if (typeof val === "string") return parseFloat(val)
28
- else return 0.0
29
- },
30
- string: (val) => {
31
- if (typeof val === "undefined") return "undefined"
32
- else if (typeof val === "boolean") return val.toString()
33
- else if (typeof val === "number") return val.toString()
34
- else if (typeof val === "string") return val
35
- else return val.toString()
36
- },
37
- default: (val, def, type) => {
38
- if (val === undefined)
39
- val = def
40
- if (type === "bool") val = globals.bool(val)
41
- else if (type === "int") val = globals.int(val)
42
- else if (type === "float") val = globals.float(val)
43
- else if (type === "string") val = globals.string(val)
44
- else throw new Error(`invalid coercion type "${type}"`)
45
- return val
46
- }
47
- }
48
- Object.keys(globals).forEach((name) => {
49
- env.addGlobal(name, globals[name])
50
- })
51
- }
52
-
@@ -1,29 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- module.exports = (env) => {
8
- /* add a "set"-like "eval" extension */
9
- class EvalExtension {
10
- constructor () {
11
- this.tags = [ "eval" ]
12
- }
13
- parse (parser, nodes, lexer) {
14
- const tok = parser.nextToken()
15
- const args = parser.parseSignature(null, true)
16
- parser.advanceAfterBlockEnd(tok.value)
17
- return new nodes.CallExtension(this, "run", args)
18
- }
19
- run (context, args) {
20
- for (const arg in args) {
21
- if (arg !== "__keywords")
22
- /* eslint no-eval: off */
23
- context.ctx[arg] = eval(args[arg])
24
- }
25
- }
26
- }
27
- env.addExtension("EvalExtension", new EvalExtension())
28
- }
29
-
@@ -1,25 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- const jsonpath = require("jsonpath")
8
-
9
- module.exports = (env) => {
10
- /* add a "jsonpath" filter */
11
- env.addFilter("jsonpath", (obj, path, count) => {
12
- let result
13
- const errs = []
14
- try {
15
- result = jsonpath.query(obj, path, count)
16
- }
17
- catch (err) {
18
- errs.push(err)
19
- }
20
- if (errs.length)
21
- return errs.join("\n")
22
- return result
23
- })
24
- }
25
-
package/nunjucks.d/pad.js DELETED
@@ -1,24 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- module.exports = (env) => {
8
- /* add a "pad" formatting filter */
9
- env.addFilter("pad", (input, num, char = " ", toRight = false) => {
10
- if (typeof input !== "string") {
11
- if (typeof input.toString === "function")
12
- input = input.toString()
13
- else
14
- input = input + ''
15
- }
16
- let result = input
17
- if (result.length < num) {
18
- const pad = (new Array(num - result.length + 1)).join(char)
19
- result = toRight ? result + pad : pad + result
20
- }
21
- return result
22
- })
23
- }
24
-
@@ -1,21 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- const sprintf = require("sprintfjs")
8
-
9
- module.exports = (env) => {
10
- /* add a "sprintf" formatting filter */
11
- env.addFilter("sprintf", (value, format, ...args) => {
12
- return sprintf(format, value, ...args)
13
- })
14
-
15
- /* add a "sprintf" global function */
16
- env.addGlobal("sprintf", (format, ...args) => {
17
- console.log(format, args)
18
- return sprintf(format, ...args)
19
- })
20
- }
21
-
@@ -1,14 +0,0 @@
1
- /*
2
- ** nunjucks -- Nunjucks Template Rendering Command-Line Interface
3
- ** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
4
- ** Licensed under MIT <http://spdx.org/licenses/MIT.html>
5
- */
6
-
7
- const UUID = require("pure-uuid")
8
-
9
- module.exports = (env) => {
10
- env.addGlobal("uuid", (...args) => {
11
- return (new UUID(...args)).format()
12
- })
13
- }
14
-
package/sample.txt DELETED
@@ -1,153 +0,0 @@
1
- ##
2
- ## Composefile -- Docker Compose Configuration
3
- ##
4
-
5
- {% set WITH_SRV_NAME = default(WITH_SRV_NAME, "ASE-K3S", "string") %}
6
- {% set WITH_SRV_DESC = default(WITH_SRV_DESC, "K3S Kubernetes Application Server (ASE)", "string") %}
7
-
8
- {% set WITH_URL_SCHEME = default(WITH_URL_SCHEME, DOCKER_STACK_URL_SCHEME, "string") %}
9
- {% set WITH_URL_HOST = default(WITH_URL_HOST, DOCKER_STACK_URL_HOST, "string") %}
10
- {% set WITH_URL_MODE = default(WITH_URL_MODE, DOCKER_STACK_URL_MODE, "string") %}
11
- {% set WITH_URL_PATH = default(WITH_URL_PATH, DOCKER_STACK_URL_PATH, "string") %}
12
-
13
- {% set WITH_WORKERS = default(WITH_WORKERS, 3, "int") %}
14
- {% set WITH_SMI = default(WITH_SMI, "no", "bool") %}
15
- {% set WITH_FAAS = default(WITH_FAAS, "no", "bool") %}
16
-
17
- version: "3.7"
18
-
19
- services:
20
-
21
- # the K3S Proxy service
22
- ase-k3s-proxy:
23
- container_name: ase-k3s-proxy
24
- image: docker.msg.team/ps/std-nginx:1.19.3-20200930
25
- init: true
26
- restart: always
27
- environment:
28
- PROXY_SRV_NAME: {{ WITH_SRV_NAME }}
29
- PROXY_SRV_DESC: {{ WITH_SRV_DESC }}
30
- PROXY_URL_SCHEME: {{ WITH_URL_SCHEME }}
31
- PROXY_URL_HOST: {{ WITH_URL_HOST }}
32
- PROXY_URL_MODE: {{ WITH_URL_MODE }}
33
- PROXY_URL_PATH: {{ WITH_URL_PATH }}
34
- PROXY_DST_PATH: {{ WITH_URL_PATH }}
35
- volumes:
36
- - ./nginx.conf:/conf/nginx.conf:ro
37
- networks:
38
- proxy:
39
- ase-k3s: { aliases: [ proxy ] }
40
- depends_on:
41
- - ase-k3s-server
42
-
43
- # the K3S Server service
44
- ase-k3s-server:
45
- hostname: node0
46
- container_name: ase-k3s-server
47
- image: docker.msg.team/ps/ase-k3s:1.22.4-20211130
48
- init: true
49
- command: >-
50
- server
51
- --bind-address=0.0.0.0
52
- --https-listen-port=6443
53
- --kube-apiserver-arg=external-hostname={{ WITH_URL_HOST }}
54
- --data-dir=/data/k3s
55
- restart: always
56
- privileged: true
57
- environment:
58
- K3S_PROXY_URL_MODE: {{ WITH_URL_MODE }}
59
- K3S_CLUSTER_SECRET: "{{ WITH_CLUSTER_SECRET }}"
60
- K3S_NODE_NAME: node0
61
- K3S_KUBECONFIG_OUTPUT: /conf/kubeconfig.yaml
62
- K3S_KUBECONFIG_MODE: 666
63
- KUBECONFIG_SERVER_URL: "{{ WITH_URL_SCHEME }}://{{ WITH_URL_HOST }}{{ WITH_URL_PATH }}"
64
- K3S_TOKEN: "foobar"
65
- ports:
66
- - 6443:6443
67
- volumes:
68
- - ase-k3s-server:/data
69
- - ./manifest-1-root.yaml:/data/k3s/server/manifests/ase-k3s-1-root.yaml
70
- {% if WITH_WORKERS > 0 %}
71
- - ./local-storage.yaml.skip:/data/k3s/server/manifests/local-storage.yaml.skip
72
- - ./manifest-2-csi.yaml:/data/k3s/server/manifests/ase-k3s-2-csi.yaml
73
- {% endif %}
74
- {% if WITH_SMI %}
75
- - ./manifest-3-smi.yaml:/data/k3s/server/manifests/ase-k3s-3-smi.yaml
76
- {% endif %}
77
- {% if WITH_FAAS %}
78
- - ./manifest-4-faas.yaml:/data/k3s/server/manifests/ase-k3s-4-kubeless.yaml
79
- {% endif %}
80
- - ./manifest-5-ui.yaml:/data/k3s/server/manifests/ase-k3s-5-ui.yaml
81
- - ./ps-kubernetes-dashboard-0.0.0.tgz:/data/k3s/server/static/charts/ps-kubernetes-dashboard-0.0.0.tgz
82
- networks:
83
- ase-k3s: { aliases: [ node0, api ] }
84
- {% if WITH_WORKERS > 0 %}
85
- depends_on:
86
- - ase-k3s-storage
87
- {% endif %}
88
-
89
- {% if WITH_WORKERS > 0 %}
90
-
91
- # the K3S Node #1
92
- {% for i in range(1, WITH_WORKERS + 1) %}
93
- ase-k3s-node-{{ i }}:
94
- hostname: node{{ i }}
95
- container_name: ase-k3s-node-{{ i }}
96
- image: docker.msg.team/ps/ase-k3s:1.22.4-20211130
97
- init: true
98
- command: >-
99
- agent
100
- --data-dir=/data/k3s
101
- restart: always
102
- privileged: true
103
- environment:
104
- K3S_URL: https://api:6443
105
- K3S_NODE_NAME: node{{ i }}
106
- K3S_TOKEN_FILE: /data-server/k3s/server/token
107
- volumes:
108
- - ase-k3s-node-{{ i }}:/data
109
- - ase-k3s-server:/data-server
110
- networks:
111
- ase-k3s: { aliases: [ node{{ i }} ] }
112
- depends_on:
113
- - ase-k3s-server
114
- - ase-k3s-storage
115
- {% endfor %}
116
-
117
- # the NFS storage service
118
- ase-k3s-storage:
119
- hostname: nfs
120
- container_name: ase-k3s-storage
121
- image: docker.msg.team/ps/std-nfs:12-20200111
122
- init: true
123
- restart: always
124
- privileged: true
125
- environment:
126
- SHARED_DIRECTORY: /data/k3s
127
- volumes:
128
- - ase-k3s-storage:/data
129
- networks:
130
- ase-k3s: { aliases: [ nfs ] }
131
-
132
- {% endif %}
133
-
134
- volumes:
135
- ase-k3s-server:
136
- name: ase-k3s-server
137
- {% if WITH_WORKERS > 0 %}
138
- {% for i in range(1, WITH_WORKERS + 1) %}
139
- ase-k3s-node-{{ i }}:
140
- name: ase-k3s-node-{{ i }}
141
- {% endfor %}
142
- ase-k3s-storage:
143
- name: ase-k3s-storage
144
- {% endif %}
145
-
146
- networks:
147
- proxy:
148
- name: proxy
149
- external: true
150
- ase-k3s:
151
- name: ase-k3s
152
- driver: bridge
153
-