@rse/nunjucks-cli 1.0.1 → 1.1.1

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 +5 -4
  2. package/nunjucks.js +12 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -37,7 +37,7 @@ $ nunjucks
37
37
  [-c|--config <config-file>]
38
38
  [-d|--defines <context-file>]
39
39
  [-D|--define <key>=<value>]
40
- [-e|--extension <extension-file>]
40
+ [-e|--extension <module-name>]
41
41
  [-o|--output <output-file>|-]
42
42
  <input-file>|-
43
43
  ```
@@ -52,8 +52,8 @@ $ nunjucks
52
52
  load context definition YAML file.
53
53
  - `-D`|`--define` `<key>=<value>`:<br/>
54
54
  set context definition key/value.
55
- - `-e`|`--extension` `default|date|eval|<extension-file>`:<br/>
56
- load Nunjucks JavaScript extension (built-in or from file).
55
+ - `-e`|`--extension` `default|date|eval|<module-name>`:<br/>
56
+ load Nunjucks JavaScript extension module (built-in or NPM installed).
57
57
  - `-o`|`--output` `<output-file>`|`-`:<br/>
58
58
  save output file (or stdout).
59
59
  - `<input-file>`|`-`:<br/>
@@ -64,12 +64,13 @@ Example
64
64
 
65
65
  ```sh
66
66
  $ echo "Hello, {{who}}!" | nunjucks -D who=world -
67
+ Hello, world!
67
68
  ```
68
69
 
69
70
  License
70
71
  -------
71
72
 
72
- Copyright (c) 2019-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)
73
+ Copyright &copy; 2019-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)
73
74
 
74
75
  Permission is hereby granted, free of charge, to any person obtaining
75
76
  a copy of this software and associated documentation files (the
package/nunjucks.js CHANGED
@@ -26,7 +26,7 @@ const argv = yargs
26
26
  "[-c|--config <config-file>] " +
27
27
  "[-d|--defines <context-file>] " +
28
28
  "[-D|--define <key>=<value>] " +
29
- "[-e|--extension <extension-file>] " +
29
+ "[-e|--extension <module-name>] " +
30
30
  "[-o|--output <output-file>|-] " +
31
31
  "<input-file>|-")
32
32
  .version(false)
@@ -35,7 +35,7 @@ const argv = yargs
35
35
  .string("c").nargs("c", 1).alias("c", "config").describe("c", "load Nunjucks configuration YAML file")
36
36
  .string("d").nargs("d", 1).alias("d", "defines").describe("d", "load context definition YAML file")
37
37
  .string("D").nargs("D", 1).alias("D", "define").describe("D", "set context definition key/value")
38
- .array("e").nargs("e", 1).alias("e", "extension").describe("e", "load Nunjucks JavaScript extension file")
38
+ .array("e").nargs("e", 1).alias("e", "extension").describe("e", "load Nunjucks JavaScript extension module")
39
39
  .string("o").nargs("o", 1).alias("o", "output").default("o", "-").describe("o", "save output file")
40
40
  .strict()
41
41
  .showHelpOnFail(true)
@@ -141,11 +141,18 @@ if (typeof argv.extension === "object" && argv.extension instanceof Array) {
141
141
  for (let extension of argv.extension) {
142
142
  if (extension.match(/^(?:default|date|eval)$/))
143
143
  extension = path.join(__dirname, "nunjucks.d", `${extension}.js`)
144
- else if (!fs.existsSync(extension)) {
145
- console.error(chalk.red(`nunjucks: ERROR: failed to find extension file: ${extension}`))
144
+ let path = null
145
+ try {
146
+ path = require.resolve(extension)
147
+ }
148
+ catch (ex) {
149
+ path = null
150
+ }
151
+ if (path === null) {
152
+ console.error(chalk.red(`nunjucks: ERROR: failed to find extension module: ${extension}`))
146
153
  process.exit(1)
147
154
  }
148
- const ext = require(path.resolve(extension))
155
+ const ext = require(extension)
149
156
  if (!(ext !== null && typeof ext === "function")) {
150
157
  console.error(chalk.red(`nunjucks: ERROR: failed to call extension file: ${extension}`))
151
158
  process.exit(1)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rse/nunjucks-cli",
3
3
  "publishConfig": { "access": "public" },
4
- "version": "1.0.1",
4
+ "version": "1.1.1",
5
5
  "description": "Nunjucks Template Rendering Command-Line Interface",
6
6
  "author": {
7
7
  "name": "Dr. Ralf S. Engelschall",