@getkist/action-nunjucks 2.0.7
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/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/actions/TemplateRenderAction/TemplateRenderAction.d.ts +49 -0
- package/dist/actions/TemplateRenderAction/TemplateRenderAction.d.ts.map +1 -0
- package/dist/actions/TemplateRenderAction/TemplateRenderAction.js +206 -0
- package/dist/actions/TemplateRenderAction/TemplateRenderAction.js.map +1 -0
- package/dist/actions/TemplateRenderAction/index.d.ts +3 -0
- package/dist/actions/TemplateRenderAction/index.d.ts.map +1 -0
- package/dist/actions/TemplateRenderAction/index.js +2 -0
- package/dist/actions/TemplateRenderAction/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Action.d.ts +60 -0
- package/dist/types/Action.d.ts.map +1 -0
- package/dist/types/Action.js +56 -0
- package/dist/types/Action.js.map +1 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 kist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @getkist/action-nunjucks
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@getkist/action-nunjucks)
|
|
4
|
+
[](https://www.npmjs.com/package/@getkist/action-nunjucks)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/getkist/kist-action-nunjucks/actions)
|
|
8
|
+
[](https://codecov.io/gh/getkist/action-nunjucks)
|
|
9
|
+
|
|
10
|
+
Jinja/Nunjucks template rendering actions for kist.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🎨 Render Nunjucks templates to files
|
|
15
|
+
- � **Directory mode** - batch render entire folders preserving structure
|
|
16
|
+
- 📝 Load context data from YAML/JSON files
|
|
17
|
+
- ⚙️ Configurable Nunjucks behaviors (autoescape, trim, lstrip)
|
|
18
|
+
- 🔤 Custom output encoding support
|
|
19
|
+
- 🚀 Useful for docs sites, static pages, and codegen
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install --save-dev @getkist/action-nunjucks
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Single File Mode
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
pipeline:
|
|
33
|
+
stages:
|
|
34
|
+
- name: render
|
|
35
|
+
steps:
|
|
36
|
+
- name: render-page
|
|
37
|
+
action: TemplateRenderAction
|
|
38
|
+
options:
|
|
39
|
+
templatePath: ./templates/page.njk
|
|
40
|
+
outputPath: ./dist/page.html
|
|
41
|
+
context:
|
|
42
|
+
title: "Welcome"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Directory Mode
|
|
46
|
+
|
|
47
|
+
Render all templates in a directory while preserving folder structure:
|
|
48
|
+
|
|
49
|
+
```yaml
|
|
50
|
+
pipeline:
|
|
51
|
+
stages:
|
|
52
|
+
- name: render
|
|
53
|
+
steps:
|
|
54
|
+
- name: render-templates
|
|
55
|
+
action: TemplateRenderAction
|
|
56
|
+
options:
|
|
57
|
+
inputDir: ./src/templates
|
|
58
|
+
outputDir: ./dist
|
|
59
|
+
pattern: "**/*.html.jinja"
|
|
60
|
+
excludePatterns:
|
|
61
|
+
- "_*.jinja"
|
|
62
|
+
- "partials/**"
|
|
63
|
+
stripExtension: ".jinja"
|
|
64
|
+
context:
|
|
65
|
+
siteName: "My Site"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This renders:
|
|
69
|
+
- `src/templates/index.html.jinja` → `dist/index.html`
|
|
70
|
+
- `src/templates/about/team.html.jinja` → `dist/about/team.html`
|
|
71
|
+
- Skips `_base.jinja` and `partials/` files
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
- **[Usage Guide](./doc/usage.md)** - YAML and programmatic examples
|
|
76
|
+
- **[Configuration](./doc/configuration.md)** - All available options
|
|
77
|
+
- **[Examples](./doc/examples.md)** - Real-world use cases
|
|
78
|
+
- **[API Reference](./doc/api.md)** - Generated TypeDoc documentation
|
|
79
|
+
- **[Troubleshooting](./doc/troubleshooting.md)** - Common issues and solutions
|
|
80
|
+
- **[Performance Guide](./doc/performance.md)** - Tips for optimization
|
|
81
|
+
|
|
82
|
+
## Actions
|
|
83
|
+
|
|
84
|
+
### TemplateRenderAction
|
|
85
|
+
|
|
86
|
+
Renders Nunjucks templates with optional context files and Nunjucks configuration.
|
|
87
|
+
|
|
88
|
+
#### Single File Mode Options
|
|
89
|
+
|
|
90
|
+
| Option | Type | Required | Description |
|
|
91
|
+
|--------|------|----------|-------------|
|
|
92
|
+
| `templatePath` | string | Yes | Path to template file |
|
|
93
|
+
| `outputPath` | string | Yes | Output file path |
|
|
94
|
+
| `context` | object | No | Template context data |
|
|
95
|
+
| `contextFiles` | string[] | No | YAML/JSON files to merge |
|
|
96
|
+
| `searchPaths` | string[] | No | Template search paths for includes |
|
|
97
|
+
| `autoescape` | boolean | No | Enable HTML escaping |
|
|
98
|
+
| `trimBlocks` | boolean | No | Trim trailing newlines from blocks |
|
|
99
|
+
| `lstripBlocks` | boolean | No | Strip leading whitespace from blocks |
|
|
100
|
+
| `outputEncoding` | string | No | File encoding (default: utf8) |
|
|
101
|
+
|
|
102
|
+
#### Directory Mode Options
|
|
103
|
+
|
|
104
|
+
| Option | Type | Required | Description |
|
|
105
|
+
|--------|------|----------|-------------|
|
|
106
|
+
| `inputDir` | string | Yes | Source directory containing templates |
|
|
107
|
+
| `outputDir` | string | Yes | Output directory for rendered files |
|
|
108
|
+
| `pattern` | string | No | Glob pattern (default: `**/*.html.jinja`) |
|
|
109
|
+
| `excludePatterns` | string[] | No | Patterns to exclude (e.g., partials) |
|
|
110
|
+
| `stripExtension` | string | No | Extension to remove (default: `.jinja`) |
|
|
111
|
+
| `context` | object | No | Shared context for all templates |
|
|
112
|
+
| `contextFiles` | string[] | No | YAML/JSON files to merge |
|
|
113
|
+
| `searchPaths` | string[] | No | Template search paths for includes |
|
|
114
|
+
| `autoescape` | boolean | No | Enable HTML escaping |
|
|
115
|
+
| `trimBlocks` | boolean | No | Trim trailing newlines from blocks |
|
|
116
|
+
| `lstripBlocks` | boolean | No | Strip leading whitespace from blocks |
|
|
117
|
+
| `outputEncoding` | string | No | File encoding (default: utf8) |
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm run build # Compile TypeScript
|
|
123
|
+
npm run test # Run tests
|
|
124
|
+
npm run lint # Check code quality
|
|
125
|
+
npm run docs # Generate API documentation
|
|
126
|
+
npm run format # Format code with Prettier
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Requirements
|
|
130
|
+
|
|
131
|
+
- Node.js >= 20.0.0
|
|
132
|
+
- npm >= 10.0.0
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Action, ActionOptionsType } from "../../types/Action.js";
|
|
2
|
+
export interface TemplateRenderActionOptions extends ActionOptionsType {
|
|
3
|
+
/** Single template file to render (mutually exclusive with inputDir) */
|
|
4
|
+
templatePath?: string;
|
|
5
|
+
/** Single output file path (mutually exclusive with outputDir) */
|
|
6
|
+
outputPath?: string;
|
|
7
|
+
/** Directory containing templates to render (enables directory mode) */
|
|
8
|
+
inputDir?: string;
|
|
9
|
+
/** Output directory for rendered templates (required with inputDir) */
|
|
10
|
+
outputDir?: string;
|
|
11
|
+
/** Glob pattern for matching templates in directory mode (default: "**\/*.html.jinja") */
|
|
12
|
+
pattern?: string;
|
|
13
|
+
/** Patterns to exclude from rendering (e.g., ["_*", "includes/**"]) */
|
|
14
|
+
excludePatterns?: string[];
|
|
15
|
+
/** Extension to strip from output filenames (default: ".jinja") */
|
|
16
|
+
stripExtension?: string;
|
|
17
|
+
context?: Record<string, unknown>;
|
|
18
|
+
searchPaths?: string[];
|
|
19
|
+
contextFiles?: string[];
|
|
20
|
+
autoescape?: boolean;
|
|
21
|
+
trimBlocks?: boolean;
|
|
22
|
+
lstripBlocks?: boolean;
|
|
23
|
+
outputEncoding?: BufferEncoding;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* TemplateRenderAction renders Nunjucks/Jinja templates to files.
|
|
27
|
+
* Supports both single-file mode (templatePath/outputPath) and
|
|
28
|
+
* directory mode (inputDir/outputDir) for batch rendering.
|
|
29
|
+
*/
|
|
30
|
+
export declare class TemplateRenderAction extends Action {
|
|
31
|
+
validateOptions(options: ActionOptionsType): boolean;
|
|
32
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Executes directory mode rendering - renders all matching templates
|
|
35
|
+
* in inputDir to outputDir, preserving folder structure.
|
|
36
|
+
*/
|
|
37
|
+
private executeDirectoryMode;
|
|
38
|
+
/**
|
|
39
|
+
* Executes single-file mode rendering.
|
|
40
|
+
*/
|
|
41
|
+
private executeSingleFile;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a configured Nunjucks environment.
|
|
44
|
+
*/
|
|
45
|
+
private createNunjucksEnv;
|
|
46
|
+
private loadContext;
|
|
47
|
+
private parseContextFile;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=TemplateRenderAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateRenderAction.d.ts","sourceRoot":"","sources":["../../../src/actions/TemplateRenderAction/TemplateRenderAction.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAQlE,MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IAClE,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,mEAAmE;IACnE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,cAAc,CAAC;CACnC;AAMD;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,MAAM;IAC5C,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO;IAyE9C,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAcxD;;;OAGG;YACW,oBAAoB;IA+ElC;;OAEG;YACW,iBAAiB;IAyC/B;;OAEG;IACH,OAAO,CAAC,iBAAiB;YAcX,WAAW;IAqBzB,OAAO,CAAC,gBAAgB;CAoB3B"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Import
|
|
3
|
+
// ============================================================================
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
import { Action } from "../../types/Action.js";
|
|
8
|
+
import nunjucks from "nunjucks";
|
|
9
|
+
import path from "path";
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Class
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* TemplateRenderAction renders Nunjucks/Jinja templates to files.
|
|
15
|
+
* Supports both single-file mode (templatePath/outputPath) and
|
|
16
|
+
* directory mode (inputDir/outputDir) for batch rendering.
|
|
17
|
+
*/
|
|
18
|
+
export class TemplateRenderAction extends Action {
|
|
19
|
+
validateOptions(options) {
|
|
20
|
+
const opts = options;
|
|
21
|
+
// Directory mode validation
|
|
22
|
+
if (opts.inputDir || opts.outputDir) {
|
|
23
|
+
if (!opts.inputDir) {
|
|
24
|
+
throw new Error("TemplateRenderAction requires 'inputDir' when using 'outputDir'");
|
|
25
|
+
}
|
|
26
|
+
if (!opts.outputDir) {
|
|
27
|
+
throw new Error("TemplateRenderAction requires 'outputDir' when using 'inputDir'");
|
|
28
|
+
}
|
|
29
|
+
if (typeof opts.inputDir !== "string") {
|
|
30
|
+
throw new Error("TemplateRenderAction 'inputDir' must be a string");
|
|
31
|
+
}
|
|
32
|
+
if (typeof opts.outputDir !== "string") {
|
|
33
|
+
throw new Error("TemplateRenderAction 'outputDir' must be a string");
|
|
34
|
+
}
|
|
35
|
+
if (opts.excludePatterns && !Array.isArray(opts.excludePatterns)) {
|
|
36
|
+
throw new Error("TemplateRenderAction 'excludePatterns' must be an array");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Single-file mode validation
|
|
41
|
+
if (!opts.templatePath) {
|
|
42
|
+
throw new Error("TemplateRenderAction requires 'templatePath' or 'inputDir'");
|
|
43
|
+
}
|
|
44
|
+
if (!opts.outputPath) {
|
|
45
|
+
throw new Error("TemplateRenderAction requires 'outputPath'");
|
|
46
|
+
}
|
|
47
|
+
if (typeof opts.templatePath !== "string") {
|
|
48
|
+
throw new Error("TemplateRenderAction 'templatePath' must be a string");
|
|
49
|
+
}
|
|
50
|
+
if (typeof opts.outputPath !== "string") {
|
|
51
|
+
throw new Error("TemplateRenderAction 'outputPath' must be a string");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (opts.searchPaths && !Array.isArray(opts.searchPaths)) {
|
|
55
|
+
throw new Error("TemplateRenderAction 'searchPaths' must be an array");
|
|
56
|
+
}
|
|
57
|
+
if (opts.contextFiles && !Array.isArray(opts.contextFiles)) {
|
|
58
|
+
throw new Error("TemplateRenderAction 'contextFiles' must be an array");
|
|
59
|
+
}
|
|
60
|
+
if (opts.outputEncoding && typeof opts.outputEncoding !== "string") {
|
|
61
|
+
throw new Error("TemplateRenderAction 'outputEncoding' must be a string");
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
async execute(options) {
|
|
66
|
+
const opts = options;
|
|
67
|
+
this.validateOptions(opts);
|
|
68
|
+
// Directory mode
|
|
69
|
+
if (opts.inputDir && opts.outputDir) {
|
|
70
|
+
await this.executeDirectoryMode(opts);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Single-file mode
|
|
74
|
+
await this.executeSingleFile(opts);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Executes directory mode rendering - renders all matching templates
|
|
78
|
+
* in inputDir to outputDir, preserving folder structure.
|
|
79
|
+
*/
|
|
80
|
+
async executeDirectoryMode(opts) {
|
|
81
|
+
const inputDir = path.resolve(opts.inputDir);
|
|
82
|
+
const outputDir = path.resolve(opts.outputDir);
|
|
83
|
+
const pattern = opts.pattern ?? "**/*.html.jinja";
|
|
84
|
+
const stripExtension = opts.stripExtension ?? ".jinja";
|
|
85
|
+
const excludePatterns = opts.excludePatterns ?? [];
|
|
86
|
+
this.logInfo(`Rendering templates from ${inputDir} to ${outputDir} (pattern: ${pattern})`);
|
|
87
|
+
// Find all matching template files
|
|
88
|
+
const templates = await glob(pattern, {
|
|
89
|
+
cwd: inputDir,
|
|
90
|
+
nodir: true,
|
|
91
|
+
ignore: excludePatterns,
|
|
92
|
+
});
|
|
93
|
+
if (templates.length === 0) {
|
|
94
|
+
this.logInfo(`No templates found matching pattern: ${pattern}`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.logInfo(`Found ${templates.length} templates to render`);
|
|
98
|
+
const context = await this.loadContext(opts);
|
|
99
|
+
const searchPaths = opts.searchPaths || [inputDir];
|
|
100
|
+
const env = this.createNunjucksEnv(opts, searchPaths);
|
|
101
|
+
let successCount = 0;
|
|
102
|
+
let errorCount = 0;
|
|
103
|
+
for (const templateRelPath of templates) {
|
|
104
|
+
// Calculate output path (strip extension, preserve structure)
|
|
105
|
+
let outputRelPath = templateRelPath;
|
|
106
|
+
if (stripExtension && outputRelPath.endsWith(stripExtension)) {
|
|
107
|
+
outputRelPath = outputRelPath.slice(0, -stripExtension.length);
|
|
108
|
+
}
|
|
109
|
+
const outputFilePath = path.join(outputDir, outputRelPath);
|
|
110
|
+
try {
|
|
111
|
+
const rendered = await new Promise((resolve, reject) => {
|
|
112
|
+
env.render(templateRelPath, context, (error, result) => {
|
|
113
|
+
if (error) {
|
|
114
|
+
reject(error);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
resolve(result ?? "");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
await fs.mkdir(path.dirname(outputFilePath), { recursive: true });
|
|
121
|
+
await fs.writeFile(outputFilePath, rendered, opts.outputEncoding || "utf8");
|
|
122
|
+
successCount++;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
errorCount++;
|
|
126
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
127
|
+
this.logError(`Failed to render ${templateRelPath}: ${message}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
this.logInfo(`Directory rendering complete: ${successCount} succeeded, ${errorCount} failed`);
|
|
131
|
+
if (errorCount > 0 && successCount === 0) {
|
|
132
|
+
throw new Error(`All ${errorCount} templates failed to render`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Executes single-file mode rendering.
|
|
137
|
+
*/
|
|
138
|
+
async executeSingleFile(opts) {
|
|
139
|
+
const templatePath = path.resolve(opts.templatePath);
|
|
140
|
+
const outputPath = path.resolve(opts.outputPath);
|
|
141
|
+
const searchPaths = opts.searchPaths || [path.dirname(templatePath)];
|
|
142
|
+
const context = await this.loadContext(opts);
|
|
143
|
+
const templateName = path.isAbsolute(templatePath)
|
|
144
|
+
? path.relative(searchPaths[0], templatePath)
|
|
145
|
+
: templatePath;
|
|
146
|
+
this.logInfo(`Rendering template ${templatePath} -> ${outputPath}`);
|
|
147
|
+
try {
|
|
148
|
+
const env = this.createNunjucksEnv(opts, searchPaths);
|
|
149
|
+
const rendered = await new Promise((resolve, reject) => {
|
|
150
|
+
env.render(templateName, context, (error, result) => {
|
|
151
|
+
if (error) {
|
|
152
|
+
reject(error);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
resolve(result ?? "");
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
159
|
+
await fs.writeFile(outputPath, rendered, opts.outputEncoding || "utf8");
|
|
160
|
+
this.logInfo("Template rendered successfully");
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
164
|
+
this.logError("TemplateRenderAction failed", error);
|
|
165
|
+
throw new Error(`Template rendering failed: ${message}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates a configured Nunjucks environment.
|
|
170
|
+
*/
|
|
171
|
+
createNunjucksEnv(opts, searchPaths) {
|
|
172
|
+
return new nunjucks.Environment(new nunjucks.FileSystemLoader(searchPaths, { noCache: true }), {
|
|
173
|
+
autoescape: opts.autoescape ?? false,
|
|
174
|
+
trimBlocks: opts.trimBlocks ?? false,
|
|
175
|
+
lstripBlocks: opts.lstripBlocks ?? false,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async loadContext(opts) {
|
|
179
|
+
const baseContext = opts.context || {};
|
|
180
|
+
if (!opts.contextFiles || opts.contextFiles.length === 0) {
|
|
181
|
+
return baseContext;
|
|
182
|
+
}
|
|
183
|
+
const loaded = {};
|
|
184
|
+
for (const filePath of opts.contextFiles) {
|
|
185
|
+
const resolved = path.resolve(filePath);
|
|
186
|
+
const content = await fs.readFile(resolved, "utf8");
|
|
187
|
+
const parsed = this.parseContextFile(content, resolved);
|
|
188
|
+
Object.assign(loaded, parsed);
|
|
189
|
+
}
|
|
190
|
+
return { ...loaded, ...baseContext };
|
|
191
|
+
}
|
|
192
|
+
parseContextFile(content, filePath) {
|
|
193
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
194
|
+
if (ext === ".json") {
|
|
195
|
+
return JSON.parse(content);
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
return yaml.load(content);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
202
|
+
throw new Error(`Failed to parse context file ${filePath}: ${message}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=TemplateRenderAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateRenderAction.js","sourceRoot":"","sources":["../../../src/actions/TemplateRenderAction/TemplateRenderAction.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAqB,MAAM,uBAAuB,CAAC;AAClE,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,IAAI,MAAM,MAAM,CAAC;AA8BxB,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,MAAM;IAC5C,eAAe,CAAC,OAA0B;QACtC,MAAM,IAAI,GAAG,OAAsC,CAAC;QAEpD,4BAA4B;QAC5B,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CACX,iEAAiE,CACpE,CAAC;YACN,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CACX,iEAAiE,CACpE,CAAC;YACN,CAAC;YACD,IAAI,O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,CAAC,KAAK,CAAC,OAAO,CAA4B,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAA4B,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,OAAO,GACT,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3D,MAAM,IAAI,KAAK,CACX,gCAAgC,QAAQ,KAAK,OAAO,EAAE,CACzD,CAAC;QACN,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/TemplateRenderAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/actions/TemplateRenderAction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActionPlugin } from "./types/Action.js";
|
|
2
|
+
import { TemplateRenderAction } from "./actions/TemplateRenderAction/index.js";
|
|
3
|
+
declare const plugin: ActionPlugin;
|
|
4
|
+
export default plugin;
|
|
5
|
+
export type { TemplateRenderActionOptions } from "./actions/TemplateRenderAction/index.js";
|
|
6
|
+
export { TemplateRenderAction };
|
|
7
|
+
export { Action, ActionPlugin, ActionOptionsType } from "./types/Action.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,QAAA,MAAM,MAAM,EAAE,YAIb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,YAAY,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TemplateRenderAction } from "./actions/TemplateRenderAction/index.js";
|
|
2
|
+
const plugin = {
|
|
3
|
+
name: "@getkist/action-nunjucks",
|
|
4
|
+
version: "2.0.2",
|
|
5
|
+
actions: { TemplateRenderAction },
|
|
6
|
+
};
|
|
7
|
+
export default plugin;
|
|
8
|
+
export { TemplateRenderAction };
|
|
9
|
+
export { Action } from "./types/Action.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,MAAM,MAAM,GAAiB;IACzB,IAAI,EAAE,0BAA0B;IAChC,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,EAAE,oBAAoB,EAAE;CACpC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,OAAO,EAAE,MAAM,EAAmC,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Action types for kist action plugins
|
|
3
|
+
* These types match the kist Action interface for compatibility
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Action options type - a generic record of key-value pairs
|
|
7
|
+
*/
|
|
8
|
+
export type ActionOptionsType = Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for all kist actions
|
|
11
|
+
* Provides logging and execution interface
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class Action<T extends ActionOptionsType = ActionOptionsType> {
|
|
14
|
+
/**
|
|
15
|
+
* Gets the unique name of the action.
|
|
16
|
+
*/
|
|
17
|
+
get name(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Validates options before execution
|
|
20
|
+
* Override in subclasses for specific validation
|
|
21
|
+
*/
|
|
22
|
+
validateOptions(_options: T): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Execute the action with given options
|
|
25
|
+
* Must be implemented by subclasses
|
|
26
|
+
*/
|
|
27
|
+
abstract execute(options: T): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Provides a description of the action
|
|
30
|
+
*/
|
|
31
|
+
describe(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Log an info message
|
|
34
|
+
*/
|
|
35
|
+
protected logInfo(message: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Log an error message
|
|
38
|
+
*/
|
|
39
|
+
protected logError(message: string, error?: unknown): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log a debug message
|
|
42
|
+
*/
|
|
43
|
+
protected logDebug(message: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Log a warning message
|
|
46
|
+
*/
|
|
47
|
+
protected logWarning(message: string): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Plugin interface for kist action packages
|
|
51
|
+
*/
|
|
52
|
+
export interface ActionPlugin {
|
|
53
|
+
/** Plugin name */
|
|
54
|
+
name: string;
|
|
55
|
+
/** Plugin version */
|
|
56
|
+
version: string;
|
|
57
|
+
/** Map of action names to action classes */
|
|
58
|
+
actions: Record<string, new () => Action>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=Action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../src/types/Action.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD;;;GAGG;AACH,8BAAsB,MAAM,CAAC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB;IACxE;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO;IAIrC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3C;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIxC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAI1D;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMzC;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAG9C;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,MAAM,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Action types for kist action plugins
|
|
3
|
+
* These types match the kist Action interface for compatibility
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class for all kist actions
|
|
7
|
+
* Provides logging and execution interface
|
|
8
|
+
*/
|
|
9
|
+
export class Action {
|
|
10
|
+
/**
|
|
11
|
+
* Gets the unique name of the action.
|
|
12
|
+
*/
|
|
13
|
+
get name() {
|
|
14
|
+
return this.constructor.name;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates options before execution
|
|
18
|
+
* Override in subclasses for specific validation
|
|
19
|
+
*/
|
|
20
|
+
validateOptions(_options) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Provides a description of the action
|
|
25
|
+
*/
|
|
26
|
+
describe() {
|
|
27
|
+
return `${this.name} action`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Log an info message
|
|
31
|
+
*/
|
|
32
|
+
logInfo(message) {
|
|
33
|
+
console.log(`[${this.name}] ${message}`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Log an error message
|
|
37
|
+
*/
|
|
38
|
+
logError(message, error) {
|
|
39
|
+
console.error(`[${this.name}] ERROR: ${message}`, error || "");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Log a debug message
|
|
43
|
+
*/
|
|
44
|
+
logDebug(message) {
|
|
45
|
+
if (process.env.DEBUG) {
|
|
46
|
+
console.debug(`[${this.name}] DEBUG: ${message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Log a warning message
|
|
51
|
+
*/
|
|
52
|
+
logWarning(message) {
|
|
53
|
+
console.warn(`[${this.name}] WARNING: ${message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=Action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.js","sourceRoot":"","sources":["../../src/types/Action.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;;GAGG;AACH,MAAM,OAAgB,MAAM;IACxB;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,QAAW;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAQD;;OAEG;IACH,QAAQ;QACJ,OAAO,GAAG,IAAI,CAAC,IAAI,SAAS,CAAC;IACjC,CAAC;IAED;;OAEG;IACO,OAAO,CAAC,OAAe;QAC7B,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACO,QAAQ,CAAC,OAAe,EAAE,KAAe;QAC/C,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,YAAY,OAAO,EAAE,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACO,QAAQ,CAAC,OAAe;QAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,YAAY,OAAO,EAAE,CAAC,CAAC;QACtD,CAAC;IACL,CAAC;IAED;;OAEG;IACO,UAAU,CAAC,OAAe;QAChC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,cAAc,OAAO,EAAE,CAAC,CAAC;IACvD,CAAC;CACJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getkist/action-nunjucks",
|
|
3
|
+
"version": "2.0.7",
|
|
4
|
+
"description": "Jinja/Nunjucks template rendering actions for kist with single-file and directory mode support",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"kist",
|
|
17
|
+
"kist-action",
|
|
18
|
+
"jinja",
|
|
19
|
+
"nunjucks",
|
|
20
|
+
"templating"
|
|
21
|
+
],
|
|
22
|
+
"author": "kist",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/getkist/kist-action-nunjucks.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/getkist/kist-action-nunjucks/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/getkist/kist-action-nunjucks#readme",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.0.0",
|
|
34
|
+
"npm": ">=10.0.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"build:watch": "tsc --watch",
|
|
39
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
|
|
40
|
+
"test:watch": "NODE_OPTIONS='--experimental-vm-modules' jest --watch",
|
|
41
|
+
"test:coverage": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage",
|
|
42
|
+
"test:unit": "NODE_OPTIONS='--experimental-vm-modules' jest --testPathPatterns=\\.test\\.ts$",
|
|
43
|
+
"test:integration": "NODE_OPTIONS='--experimental-vm-modules' jest --testPathPatterns=\\.integration\\.test\\.ts$",
|
|
44
|
+
"test:e2e": "NODE_OPTIONS='--experimental-vm-modules' jest --testPathPatterns=e2e\\.test\\.ts$",
|
|
45
|
+
"test:coverage:enforce": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage && jest --listTests | grep -E '\\.(test|integration|e2e)\\.ts$' | wc -l && echo 'Coverage thresholds enforced'",
|
|
46
|
+
"benchmark": "npx ts-node src/tests/benchmark.ts",
|
|
47
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
48
|
+
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
|
49
|
+
"format": "prettier --write 'src/**/*.ts'",
|
|
50
|
+
"docs": "typedoc",
|
|
51
|
+
"docs:watch": "typedoc --watch",
|
|
52
|
+
"clean": "rm -rf dist docs/api coverage",
|
|
53
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"kist": ">=0.1.58"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"glob": "^13.0.1",
|
|
60
|
+
"js-yaml": "^4.1.1",
|
|
61
|
+
"nunjucks": "^3.2.4"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/jest": "30.0.0",
|
|
65
|
+
"@types/js-yaml": "^4.0.9",
|
|
66
|
+
"@types/node": "25.2.2",
|
|
67
|
+
"@types/nunjucks": "^3.2.6",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "8.54.0",
|
|
69
|
+
"@typescript-eslint/parser": "8.54.0",
|
|
70
|
+
"eslint": "10.0.0",
|
|
71
|
+
"jest": "30.2.0",
|
|
72
|
+
"ts-jest": "^29.4.6",
|
|
73
|
+
"typedoc": "^0.28.0",
|
|
74
|
+
"typedoc-plugin-markdown": "^4.10.0",
|
|
75
|
+
"typescript": "^5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"files": [
|
|
78
|
+
"dist",
|
|
79
|
+
"README.md",
|
|
80
|
+
"LICENSE"
|
|
81
|
+
],
|
|
82
|
+
"sideEffects": false
|
|
83
|
+
}
|