@rse/nunjucks-cli 1.3.0 → 1.4.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.
Files changed (3) hide show
  1. package/README.md +4 -1
  2. package/nunjucks.js +21 -10
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -48,6 +48,7 @@ Options
48
48
  $ nunjucks
49
49
  [-h|--help] [-V|--version]
50
50
  [-c|--config <config-file>]
51
+ [-C|--option <key>=<value>]
51
52
  [-d|--defines <context-file>]
52
53
  [-D|--define <key>=<value>]
53
54
  [-e|--extension <module-name>]
@@ -60,7 +61,9 @@ $ nunjucks
60
61
  - `-V`|`--version`:<br/>
61
62
  show program version information.
62
63
  - `-c`|`--config` `<config-file>`:<br/>
63
- load Nunjucks configuration YAML file
64
+ load Nunjucks configuration YAML file.
65
+ - `-C`|`--option` `<key>=<value>`:<br/>
66
+ set Nunjucks configuration option.
64
67
  - `-d`|`--defines` `<context-file>`:<br/>
65
68
  load context definition YAML file.
66
69
  - `-D`|`--define` `<key>=<value>`:<br/>
package/nunjucks.js CHANGED
@@ -24,6 +24,7 @@ const argv = yargs
24
24
  "[-h|--help] " +
25
25
  "[-V|--version] " +
26
26
  "[-c|--config <config-file>] " +
27
+ "[-C|--option <key>=<value>] " +
27
28
  "[-d|--defines <context-file>] " +
28
29
  "[-D|--define <key>=<value>] " +
29
30
  "[-e|--extension <module-name>] " +
@@ -33,13 +34,19 @@ const argv = yargs
33
34
  .help("h").alias("h", "help").default("h", false).describe("h", "show usage help")
34
35
  .boolean("V").alias("V", "version").describe("V", "show program version information")
35
36
  .string("c").nargs("c", 1).alias("c", "config").describe("c", "load Nunjucks configuration YAML file")
37
+ .array("C").nargs("C", 1).alias("C", "option").describe("C", "set Nunjucks configuration option")
36
38
  .string("d").nargs("d", 1).alias("d", "defines").describe("d", "load context definition YAML file")
37
- .string("D").nargs("D", 1).alias("D", "define").describe("D", "set context definition key/value")
39
+ .array("D").nargs("D", 1).alias("D", "define").describe("D", "set context definition key/value")
38
40
  .array("e").nargs("e", 1).alias("e", "extension").describe("e", "load Nunjucks JavaScript extension module")
39
41
  .string("o").nargs("o", 1).alias("o", "output").default("o", "-").describe("o", "save output file")
40
42
  .strict()
41
43
  .showHelpOnFail(true)
42
44
  .demand(0)
45
+ .parserConfiguration({
46
+ "short-option-groups": true,
47
+ "parse-numbers": true,
48
+ "boolean-negation": true
49
+ })
43
50
  .parse(process.argv.slice(2))
44
51
 
45
52
  /* handle special version request */
@@ -103,8 +110,6 @@ context.env = process.env
103
110
 
104
111
  /* add context defines */
105
112
  if (argv.define) {
106
- if (typeof argv.define === "string")
107
- argv.define = [ argv.define ]
108
113
  argv.define.forEach((define) => {
109
114
  let [ , key, val ] = define.match(/^([^=]+)(?:=(.*))?$/)
110
115
  if (val === undefined)
@@ -124,8 +129,12 @@ if (argv.config) {
124
129
  process.exit(1)
125
130
  }
126
131
  }
132
+ if (argv.options) {
133
+ console.log(argv.options)
134
+ options = Object.assign(options, argv.options)
135
+ }
127
136
  options = Object.assign({}, {
128
- autoescape: true,
137
+ autoescape: false,
129
138
  throwOnUndefined: false,
130
139
  trimBlocks: true,
131
140
  lstripBlocks: true,
@@ -139,12 +148,14 @@ const env = nunjucks.configure(inputFile, options)
139
148
  /* load external extension files */
140
149
  if (typeof argv.extension === "object" && argv.extension instanceof Array) {
141
150
  for (let extension of argv.extension) {
142
- let modpath = null
143
- try {
144
- modpath = require.resolve(extension)
145
- }
146
- catch (ex) {
147
- modpath = null
151
+ let modpath = path.resolve(extension)
152
+ if (!fs.existsSync(modpath)) {
153
+ try {
154
+ modpath = require.resolve(extension)
155
+ }
156
+ catch (ex) {
157
+ modpath = null
158
+ }
148
159
  }
149
160
  if (modpath === null) {
150
161
  console.error(chalk.red(`nunjucks: ERROR: failed to find extension module: ${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.3.0",
4
+ "version": "1.4.0",
5
5
  "description": "Nunjucks Template Rendering Command-Line Interface",
6
6
  "author": {
7
7
  "name": "Dr. Ralf S. Engelschall",
@@ -29,7 +29,7 @@
29
29
  "eslint": "8.47.0",
30
30
  "eslint-config-standard": "17.1.0",
31
31
  "eslint-plugin-promise": "6.1.1",
32
- "eslint-plugin-import": "2.28.0",
32
+ "eslint-plugin-import": "2.28.1",
33
33
  "eslint-plugin-node": "11.1.0"
34
34
  },
35
35
  "upd": [ "!chalk" ],