kist 0.1.38 → 0.1.39

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.
@@ -3,6 +3,7 @@ import { ActionOptionsType } from "../../types/ActionOptionsType";
3
3
  export declare class TemplateRenderAction extends Action {
4
4
  execute(options: ActionOptionsType): Promise<void>;
5
5
  private renderTemplate;
6
+ private mergeContextFiles;
6
7
  describe(): string;
7
8
  }
8
9
  export default TemplateRenderAction;
@@ -28,9 +28,11 @@ const nunjucks_config_js_1 = __importDefault(require("./nunjucks.config.js"));
28
28
  class TemplateRenderAction extends Action_1.Action {
29
29
  execute(options) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
- const { templatesDir = "./templates", outputDir = "./dist", templates = [], context = {}, renderAllFromDir = false, customConfig = {}, } = options;
31
+ const { templatesDir = "./templates", outputDir = "./dist", templates = [], context = {}, contextFiles = [], renderAllFromDir = false, customConfig = {}, } = options;
32
32
  const config = Object.assign(Object.assign({}, nunjucks_config_js_1.default), customConfig);
33
33
  nunjucks_1.default.configure(templatesDir, config);
34
+ // Load and merge all JSON context files
35
+ const mergedContext = yield this.mergeContextFiles(context, contextFiles);
34
36
  try {
35
37
  if (renderAllFromDir) {
36
38
  this.logInfo(`Auto-rendering all templates from ${templatesDir}...`);
@@ -39,7 +41,7 @@ class TemplateRenderAction extends Action_1.Action {
39
41
  });
40
42
  for (const templateRelPath of templateFiles) {
41
43
  const outputFile = path_1.default.join(outputDir, templateRelPath.replace(/\.jinja$/, ""));
42
- yield this.renderTemplate(templateRelPath, outputFile, context, templatesDir);
44
+ yield this.renderTemplate(templateRelPath, outputFile, mergedContext, templatesDir);
43
45
  }
44
46
  }
45
47
  else {
@@ -47,7 +49,7 @@ class TemplateRenderAction extends Action_1.Action {
47
49
  throw new Error("Option 'templates' must be provided if 'renderAllFromDir' is false.");
48
50
  }
49
51
  for (const { template, outputFile } of templates) {
50
- yield this.renderTemplate(template, outputFile, context, templatesDir);
52
+ yield this.renderTemplate(template, outputFile, mergedContext, templatesDir);
51
53
  }
52
54
  }
53
55
  this.logInfo("✓ All templates rendered successfully.");
@@ -68,12 +70,26 @@ class TemplateRenderAction extends Action_1.Action {
68
70
  this.logInfo(`✓ Rendered: ${outputFile}`);
69
71
  });
70
72
  }
73
+ mergeContextFiles(baseContext, files) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ let merged = Object.assign({}, baseContext);
76
+ for (const file of files) {
77
+ try {
78
+ const content = yield (0, promises_1.readFile)(file, "utf-8");
79
+ const parsed = JSON.parse(content);
80
+ merged = Object.assign(Object.assign({}, merged), parsed);
81
+ }
82
+ catch (error) {
83
+ this.logWarn(`Skipping context file due to error: ${file}`);
84
+ this.logError("Context file parsing failed", error);
85
+ }
86
+ }
87
+ return merged;
88
+ });
89
+ }
71
90
  describe() {
72
- return "Renders one or many Nunjucks templates using a shared context. Supports folder-wide auto-rendering.";
91
+ return "Renders one or many Nunjucks templates using a shared context or context files. Supports folder-wide auto-rendering.";
73
92
  }
74
93
  }
75
94
  exports.TemplateRenderAction = TemplateRenderAction;
76
- // ============================================================================
77
- // Export
78
- // ============================================================================
79
95
  exports.default = TemplateRenderAction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kist",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "Package Pipeline Processor",
5
5
  "keywords": [
6
6
  "kist",
@@ -2,7 +2,7 @@
2
2
  // Imports
3
3
  // ============================================================================
4
4
 
5
- import { mkdir, writeFile } from "fs/promises";
5
+ import { mkdir, readFile, writeFile } from "fs/promises";
6
6
  import { glob } from "glob";
7
7
  import nunjucks from "nunjucks";
8
8
  import path from "path";
@@ -21,6 +21,7 @@ export class TemplateRenderAction extends Action {
21
21
  outputDir = "./dist",
22
22
  templates = [],
23
23
  context = {},
24
+ contextFiles = [],
24
25
  renderAllFromDir = false,
25
26
  customConfig = {},
26
27
  } = options;
@@ -28,6 +29,12 @@ export class TemplateRenderAction extends Action {
28
29
  const config = { ...nunjucksConfig, ...customConfig };
29
30
  nunjucks.configure(templatesDir, config);
30
31
 
32
+ // Load and merge all JSON context files
33
+ const mergedContext = await this.mergeContextFiles(
34
+ context,
35
+ contextFiles,
36
+ );
37
+
31
38
  try {
32
39
  if (renderAllFromDir) {
33
40
  this.logInfo(
@@ -45,7 +52,7 @@ export class TemplateRenderAction extends Action {
45
52
  await this.renderTemplate(
46
53
  templateRelPath,
47
54
  outputFile,
48
- context,
55
+ mergedContext,
49
56
  templatesDir,
50
57
  );
51
58
  }
@@ -60,7 +67,7 @@ export class TemplateRenderAction extends Action {
60
67
  await this.renderTemplate(
61
68
  template,
62
69
  outputFile,
63
- context,
70
+ mergedContext,
64
71
  templatesDir,
65
72
  );
66
73
  }
@@ -89,13 +96,29 @@ export class TemplateRenderAction extends Action {
89
96
  this.logInfo(`✓ Rendered: ${outputFile}`);
90
97
  }
91
98
 
99
+ private async mergeContextFiles(
100
+ baseContext: Record<string, any>,
101
+ files: string[],
102
+ ): Promise<Record<string, any>> {
103
+ let merged = { ...baseContext };
104
+
105
+ for (const file of files) {
106
+ try {
107
+ const content = await readFile(file, "utf-8");
108
+ const parsed = JSON.parse(content);
109
+ merged = { ...merged, ...parsed };
110
+ } catch (error) {
111
+ this.logWarn(`Skipping context file due to error: ${file}`);
112
+ this.logError("Context file parsing failed", error);
113
+ }
114
+ }
115
+
116
+ return merged;
117
+ }
118
+
92
119
  describe(): string {
93
- return "Renders one or many Nunjucks templates using a shared context. Supports folder-wide auto-rendering.";
120
+ return "Renders one or many Nunjucks templates using a shared context or context files. Supports folder-wide auto-rendering.";
94
121
  }
95
122
  }
96
123
 
97
- // ============================================================================
98
- // Export
99
- // ============================================================================
100
-
101
124
  export default TemplateRenderAction;