kist 0.1.37 → 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;
@@ -1,10 +1,8 @@
1
1
  import { ConfigInterface } from "../../interface/ConfigInterface";
2
2
  import { AbstractProcess } from "../abstract/AbstractProcess";
3
3
  /**
4
- * ConfigLoader is responsible for loading and parsing configuration files
5
- * (`kist.yaml` or `kist.yml` by default). It validates the configuration
6
- * structure and provides it in a usable format for the pipeline.
7
- * Extends `AbstractProcess` for consistent logging.
4
+ * ConfigLoader is responsible for loading and parsing configuration files.
5
+ * Supports a custom path via `--config`, and falls back to `kist.yaml` or `kist.yml`.
8
6
  */
9
7
  export declare class ConfigLoader extends AbstractProcess {
10
8
  /**
@@ -15,21 +13,12 @@ export declare class ConfigLoader extends AbstractProcess {
15
13
  * Default filenames to search for configuration files.
16
14
  */
17
15
  private readonly defaultFilenames;
18
- /**
19
- * Constructs a ConfigLoader instance.
20
- * Searches for `kist.yaml` or `kist.yml` in the working directory
21
- * unless a custom path is provided.
22
- *
23
- * @param configPath - Optional custom configuration file path.
24
- */
25
- constructor(configPath?: string);
16
+ constructor();
26
17
  /**
27
18
  * Initializes the loader by locating the configuration file.
28
- * Searches for `kist.yaml` or `kist.yml` by default.
29
- *
30
- * @param configPath - Optional custom configuration file path.
19
+ * Uses `--config` CLI flag if provided, otherwise defaults.
31
20
  */
32
- initialize(configPath?: string): Promise<void>;
21
+ initialize(): Promise<void>;
33
22
  /**
34
23
  * Loads and validates the configuration file.
35
24
  *
@@ -19,27 +19,19 @@ exports.ConfigLoader = void 0;
19
19
  const fs_1 = __importDefault(require("fs"));
20
20
  const js_yaml_1 = __importDefault(require("js-yaml"));
21
21
  const path_1 = __importDefault(require("path"));
22
+ const ArgumentParser_1 = require("../../cli/ArgumentParser");
22
23
  const AbstractProcess_1 = require("../abstract/AbstractProcess");
23
24
  // ============================================================================
24
25
  // Class
25
26
  // ============================================================================
26
27
  /**
27
- * ConfigLoader is responsible for loading and parsing configuration files
28
- * (`kist.yaml` or `kist.yml` by default). It validates the configuration
29
- * structure and provides it in a usable format for the pipeline.
30
- * Extends `AbstractProcess` for consistent logging.
28
+ * ConfigLoader is responsible for loading and parsing configuration files.
29
+ * Supports a custom path via `--config`, and falls back to `kist.yaml` or `kist.yml`.
31
30
  */
32
31
  class ConfigLoader extends AbstractProcess_1.AbstractProcess {
33
32
  // Constructor
34
33
  // ========================================================================
35
- /**
36
- * Constructs a ConfigLoader instance.
37
- * Searches for `kist.yaml` or `kist.yml` in the working directory
38
- * unless a custom path is provided.
39
- *
40
- * @param configPath - Optional custom configuration file path.
41
- */
42
- constructor(configPath) {
34
+ constructor() {
43
35
  super();
44
36
  // Parameters
45
37
  // ========================================================================
@@ -51,27 +43,22 @@ class ConfigLoader extends AbstractProcess_1.AbstractProcess {
51
43
  * Default filenames to search for configuration files.
52
44
  */
53
45
  this.defaultFilenames = ["kist.yaml", "kist.yml"];
54
- if (configPath) {
55
- this.configPath = path_1.default.resolve(process.cwd(), configPath);
56
- this.logDebug(`Custom configuration path set: ${this.configPath}`);
57
- }
58
- else {
59
- this.logDebug("ConfigLoader initialized without custom path.");
60
- }
46
+ this.logDebug("ConfigLoader initialized.");
61
47
  }
62
48
  // Methods
63
49
  // ========================================================================
64
50
  /**
65
51
  * Initializes the loader by locating the configuration file.
66
- * Searches for `kist.yaml` or `kist.yml` by default.
67
- *
68
- * @param configPath - Optional custom configuration file path.
52
+ * Uses `--config` CLI flag if provided, otherwise defaults.
69
53
  */
70
- initialize(configPath) {
54
+ initialize() {
71
55
  return __awaiter(this, void 0, void 0, function* () {
72
- const searchPaths = configPath ? [configPath] : this.defaultFilenames;
56
+ const parser = new ArgumentParser_1.ArgumentParser();
57
+ const cliFlags = parser.getAllFlags();
58
+ const cliPath = typeof cliFlags.config === "string" ? cliFlags.config : undefined;
59
+ const searchPaths = cliPath ? [cliPath] : this.defaultFilenames;
73
60
  this.logDebug(`Current working directory: ${process.cwd()}`);
74
- this.logDebug("Searching for configuration files...");
61
+ this.logDebug(`Searching for config file${cliPath ? ` from --config=${cliPath}` : ""}...`);
75
62
  for (const fileName of searchPaths) {
76
63
  const resolvedPath = path_1.default.resolve(process.cwd(), fileName);
77
64
  this.logDebug(`Checking: ${resolvedPath}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kist",
3
- "version": "0.1.37",
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;
@@ -5,6 +5,7 @@
5
5
  import fs from "fs";
6
6
  import yaml from "js-yaml";
7
7
  import path from "path";
8
+ import { ArgumentParser } from "../../cli/ArgumentParser";
8
9
  import { ConfigInterface } from "../../interface/ConfigInterface";
9
10
  import { AbstractProcess } from "../abstract/AbstractProcess";
10
11
 
@@ -13,10 +14,8 @@ import { AbstractProcess } from "../abstract/AbstractProcess";
13
14
  // ============================================================================
14
15
 
15
16
  /**
16
- * ConfigLoader is responsible for loading and parsing configuration files
17
- * (`kist.yaml` or `kist.yml` by default). It validates the configuration
18
- * structure and provides it in a usable format for the pipeline.
19
- * Extends `AbstractProcess` for consistent logging.
17
+ * ConfigLoader is responsible for loading and parsing configuration files.
18
+ * Supports a custom path via `--config`, and falls back to `kist.yaml` or `kist.yml`.
20
19
  */
21
20
  export class ConfigLoader extends AbstractProcess {
22
21
  // Parameters
@@ -35,21 +34,9 @@ export class ConfigLoader extends AbstractProcess {
35
34
  // Constructor
36
35
  // ========================================================================
37
36
 
38
- /**
39
- * Constructs a ConfigLoader instance.
40
- * Searches for `kist.yaml` or `kist.yml` in the working directory
41
- * unless a custom path is provided.
42
- *
43
- * @param configPath - Optional custom configuration file path.
44
- */
45
- constructor(configPath?: string) {
37
+ constructor() {
46
38
  super();
47
- if (configPath) {
48
- this.configPath = path.resolve(process.cwd(), configPath);
49
- this.logDebug(`Custom configuration path set: ${this.configPath}`);
50
- } else {
51
- this.logDebug("ConfigLoader initialized without custom path.");
52
- }
39
+ this.logDebug("ConfigLoader initialized.");
53
40
  }
54
41
 
55
42
  // Methods
@@ -57,15 +44,20 @@ export class ConfigLoader extends AbstractProcess {
57
44
 
58
45
  /**
59
46
  * Initializes the loader by locating the configuration file.
60
- * Searches for `kist.yaml` or `kist.yml` by default.
61
- *
62
- * @param configPath - Optional custom configuration file path.
47
+ * Uses `--config` CLI flag if provided, otherwise defaults.
63
48
  */
64
- public async initialize(configPath?: string): Promise<void> {
65
- const searchPaths = configPath ? [configPath] : this.defaultFilenames;
49
+ public async initialize(): Promise<void> {
50
+ const parser = new ArgumentParser();
51
+ const cliFlags = parser.getAllFlags();
52
+ const cliPath =
53
+ typeof cliFlags.config === "string" ? cliFlags.config : undefined;
54
+
55
+ const searchPaths = cliPath ? [cliPath] : this.defaultFilenames;
66
56
 
67
57
  this.logDebug(`Current working directory: ${process.cwd()}`);
68
- this.logDebug("Searching for configuration files...");
58
+ this.logDebug(
59
+ `Searching for config file${cliPath ? ` from --config=${cliPath}` : ""}...`,
60
+ );
69
61
 
70
62
  for (const fileName of searchPaths) {
71
63
  const resolvedPath = path.resolve(process.cwd(), fileName);