kist 0.0.0 → 0.1.31

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 (237) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +298 -3
  3. package/js/actions/CoreActions.d.ts +6 -0
  4. package/js/actions/CoreActions.js +47 -0
  5. package/js/actions/DirectoryCleanAction/DirectoryCleanAction.d.ts +36 -0
  6. package/js/actions/DirectoryCleanAction/DirectoryCleanAction.js +123 -0
  7. package/js/actions/DirectoryCleanAction/index.d.ts +2 -0
  8. package/js/actions/DirectoryCleanAction/index.js +8 -0
  9. package/js/actions/DirectoryCopyAction/DirectoryCopyAction.d.ts +42 -0
  10. package/js/actions/DirectoryCopyAction/DirectoryCopyAction.js +118 -0
  11. package/js/actions/DirectoryCopyAction/index.d.ts +2 -0
  12. package/js/actions/DirectoryCopyAction/index.js +8 -0
  13. package/js/actions/DirectoryCreateAction/DirectoryCreateAction.d.ts +30 -0
  14. package/js/actions/DirectoryCreateAction/DirectoryCreateAction.js +85 -0
  15. package/js/actions/DirectoryCreateAction/index.d.ts +2 -0
  16. package/js/actions/DirectoryCreateAction/index.js +8 -0
  17. package/js/actions/DocumentationAction/DocumentationAction.d.ts +23 -0
  18. package/js/actions/DocumentationAction/DocumentationAction.js +88 -0
  19. package/js/actions/DocumentationAction/index.d.ts +2 -0
  20. package/js/actions/DocumentationAction/index.js +8 -0
  21. package/js/actions/FileCopyAction/FileCopyAction.d.ts +42 -0
  22. package/js/actions/FileCopyAction/FileCopyAction.js +127 -0
  23. package/js/actions/FileCopyAction/index.d.ts +2 -0
  24. package/js/actions/FileCopyAction/index.js +8 -0
  25. package/js/actions/FileRenameAction/FileRenameAction.d.ts +30 -0
  26. package/js/actions/FileRenameAction/FileRenameAction.js +84 -0
  27. package/js/actions/FileRenameAction/index.d.ts +2 -0
  28. package/js/actions/FileRenameAction/index.js +8 -0
  29. package/js/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.d.ts +31 -0
  30. package/js/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.js +98 -0
  31. package/js/actions/JavaScriptMinifyAction/index.d.ts +2 -0
  32. package/js/actions/JavaScriptMinifyAction/index.js +8 -0
  33. package/js/actions/JavaScriptMinifyAction/terser.config.d.ts +27 -0
  34. package/js/actions/JavaScriptMinifyAction/terser.config.js +119 -0
  35. package/js/actions/LintAction/LintAction.d.ts +17 -0
  36. package/js/actions/LintAction/LintAction.js +63 -0
  37. package/js/actions/LintAction/index.d.ts +2 -0
  38. package/js/actions/LintAction/index.js +8 -0
  39. package/js/actions/PackageManagerAction/PackageManagerAction.d.ts +57 -0
  40. package/js/actions/PackageManagerAction/PackageManagerAction.js +161 -0
  41. package/js/actions/PackageManagerAction/index.d.ts +2 -0
  42. package/js/actions/PackageManagerAction/index.js +8 -0
  43. package/js/actions/PackageManagerAction/package.config.d.ts +16 -0
  44. package/js/actions/PackageManagerAction/package.config.js +91 -0
  45. package/js/actions/StyleProcessingAction/StyleProcessingAction.d.ts +34 -0
  46. package/js/actions/StyleProcessingAction/StyleProcessingAction.js +164 -0
  47. package/js/actions/StyleProcessingAction/index.d.ts +2 -0
  48. package/js/actions/StyleProcessingAction/index.js +8 -0
  49. package/js/actions/StyleProcessingAction/postcss.config.compressed.d.ts +10 -0
  50. package/js/actions/StyleProcessingAction/postcss.config.compressed.js +31 -0
  51. package/js/actions/StyleProcessingAction/postcss.config.expanded.d.ts +16 -0
  52. package/js/actions/StyleProcessingAction/postcss.config.expanded.js +45 -0
  53. package/js/actions/SvgPackagerAction/SvgPackagerAction.d.ts +68 -0
  54. package/js/actions/SvgPackagerAction/SvgPackagerAction.js +186 -0
  55. package/js/actions/SvgPackagerAction/index.d.ts +2 -0
  56. package/js/actions/SvgPackagerAction/index.js +8 -0
  57. package/js/actions/SvgReaderAction/SvgReaderAction.d.ts +32 -0
  58. package/js/actions/SvgReaderAction/SvgReaderAction.js +87 -0
  59. package/js/actions/SvgReaderAction/index.d.ts +2 -0
  60. package/js/actions/SvgReaderAction/index.js +8 -0
  61. package/js/actions/SvgSpriteAction/SvgSpriteAction.d.ts +37 -0
  62. package/js/actions/SvgSpriteAction/SvgSpriteAction.js +114 -0
  63. package/js/actions/SvgSpriteAction/index.d.ts +2 -0
  64. package/js/actions/SvgSpriteAction/index.js +8 -0
  65. package/js/actions/SvgSpriteAction/svgsprite.config.d.ts +3 -0
  66. package/js/actions/SvgSpriteAction/svgsprite.config.js +117 -0
  67. package/js/actions/SvgToPngAction/SvgToPngAction.d.ts +28 -0
  68. package/js/actions/SvgToPngAction/SvgToPngAction.js +108 -0
  69. package/js/actions/SvgToPngAction/index.d.ts +2 -0
  70. package/js/actions/SvgToPngAction/index.js +8 -0
  71. package/js/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts +28 -0
  72. package/js/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js +96 -0
  73. package/js/actions/TypeScriptCompilerAction/index.d.ts +2 -0
  74. package/js/actions/TypeScriptCompilerAction/index.js +8 -0
  75. package/js/actions/VersionWriteAction/VersionWriteAction.d.ts +45 -0
  76. package/js/actions/VersionWriteAction/VersionWriteAction.js +147 -0
  77. package/js/actions/VersionWriteAction/index.d.ts +2 -0
  78. package/js/actions/VersionWriteAction/index.js +8 -0
  79. package/js/cli/ArgumentParser.d.ts +62 -0
  80. package/js/cli/ArgumentParser.js +118 -0
  81. package/js/cli.d.ts +6 -0
  82. package/js/cli.js +58 -0
  83. package/js/core/abstract/AbstractProcess.d.ts +62 -0
  84. package/js/core/abstract/AbstractProcess.js +96 -0
  85. package/js/core/abstract/AbstractValidator.d.ts +72 -0
  86. package/js/core/abstract/AbstractValidator.js +128 -0
  87. package/js/core/config/ConfigLoader.d.ts +47 -0
  88. package/js/core/config/ConfigLoader.js +130 -0
  89. package/js/core/config/ConfigStore.d.ts +53 -0
  90. package/js/core/config/ConfigStore.js +136 -0
  91. package/js/core/config/defaultConfig.d.ts +5 -0
  92. package/js/core/config/defaultConfig.js +131 -0
  93. package/js/core/pipeline/Action.d.ts +60 -0
  94. package/js/core/pipeline/Action.js +77 -0
  95. package/js/core/pipeline/ActionRegistry.d.ts +80 -0
  96. package/js/core/pipeline/ActionRegistry.js +180 -0
  97. package/js/core/pipeline/Pipeline.d.ts +42 -0
  98. package/js/core/pipeline/Pipeline.js +107 -0
  99. package/js/core/pipeline/PipelineManager.d.ts +55 -0
  100. package/js/core/pipeline/PipelineManager.js +164 -0
  101. package/js/core/pipeline/Stage.d.ts +45 -0
  102. package/js/core/pipeline/Stage.js +110 -0
  103. package/js/core/pipeline/Step.d.ts +26 -0
  104. package/js/core/pipeline/Step.js +85 -0
  105. package/js/core/validation/OptionsValidator.d.ts +43 -0
  106. package/js/core/validation/OptionsValidator.js +123 -0
  107. package/js/index.d.ts +3 -0
  108. package/js/index.js +36 -0
  109. package/js/interface/ActionInterface.d.ts +57 -0
  110. package/js/interface/ActionInterface.js +5 -0
  111. package/js/interface/ActionPlugin.d.ts +4 -0
  112. package/js/interface/ActionPlugin.js +5 -0
  113. package/js/interface/ConfigInterface.d.ts +43 -0
  114. package/js/interface/ConfigInterface.js +5 -0
  115. package/js/interface/LiveOptionsInterface.d.ts +42 -0
  116. package/js/interface/LiveOptionsInterface.js +2 -0
  117. package/js/interface/MetadataInterface.d.ts +95 -0
  118. package/js/interface/MetadataInterface.js +2 -0
  119. package/js/interface/OptionsInterface.d.ts +45 -0
  120. package/js/interface/OptionsInterface.js +5 -0
  121. package/js/interface/PipelineOptionsInterface.d.ts +66 -0
  122. package/js/interface/PipelineOptionsInterface.js +5 -0
  123. package/js/interface/StageInterface.d.ts +79 -0
  124. package/js/interface/StageInterface.js +5 -0
  125. package/js/interface/StepInterface.d.ts +66 -0
  126. package/js/interface/StepInterface.js +5 -0
  127. package/js/interface/StepOptionsInterface.d.ts +38 -0
  128. package/js/interface/StepOptionsInterface.js +21 -0
  129. package/js/interface/index.d.ts +7 -0
  130. package/js/interface/index.js +3 -0
  131. package/js/kist.d.ts +58 -0
  132. package/js/kist.js +145 -0
  133. package/js/live/LiveServer.d.ts +95 -0
  134. package/js/live/LiveServer.js +233 -0
  135. package/js/live/LiveWatcher.d.ts +45 -0
  136. package/js/live/LiveWatcher.js +140 -0
  137. package/js/logger/Logger.d.ts +94 -0
  138. package/js/logger/Logger.js +151 -0
  139. package/js/logger/LoggerStyles.d.ts +23 -0
  140. package/js/logger/LoggerStyles.js +30 -0
  141. package/js/types/ActionOptionsType.d.ts +8 -0
  142. package/js/types/ActionOptionsType.js +2 -0
  143. package/js/types/index.d.ts +1 -0
  144. package/js/types/index.js +3 -0
  145. package/package.json +93 -7
  146. package/ts/actions/CoreActions.ts +64 -0
  147. package/ts/actions/DirectoryCleanAction/DirectoryCleanAction.ts +121 -0
  148. package/ts/actions/DirectoryCleanAction/index.ts +11 -0
  149. package/ts/actions/DirectoryCopyAction/DirectoryCopyAction.ts +118 -0
  150. package/ts/actions/DirectoryCopyAction/index.ts +11 -0
  151. package/ts/actions/DirectoryCreateAction/DirectoryCreateAction.ts +81 -0
  152. package/ts/actions/DirectoryCreateAction/index.ts +11 -0
  153. package/ts/actions/DocumentationAction/DocumentationAction.ts +100 -0
  154. package/ts/actions/DocumentationAction/index.ts +11 -0
  155. package/ts/actions/FileCopyAction/FileCopyAction.ts +125 -0
  156. package/ts/actions/FileCopyAction/index.ts +11 -0
  157. package/ts/actions/FileRenameAction/FileRenameAction.ts +82 -0
  158. package/ts/actions/FileRenameAction/index.ts +11 -0
  159. package/ts/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.ts +109 -0
  160. package/ts/actions/JavaScriptMinifyAction/index.ts +11 -0
  161. package/ts/actions/JavaScriptMinifyAction/terser.config.ts +177 -0
  162. package/ts/actions/LintAction/LintAction.ts +67 -0
  163. package/ts/actions/LintAction/index.ts +11 -0
  164. package/ts/actions/PackageManagerAction/PackageManagerAction.ts +176 -0
  165. package/ts/actions/PackageManagerAction/index.ts +11 -0
  166. package/ts/actions/PackageManagerAction/package.config.ts +94 -0
  167. package/ts/actions/SassDocAction/SassDocAction.ts +66 -0
  168. package/ts/actions/SassDocAction/index.ts +11 -0
  169. package/ts/actions/StyleProcessingAction/StyleProcessingAction.ts +142 -0
  170. package/ts/actions/StyleProcessingAction/index.ts +11 -0
  171. package/ts/actions/StyleProcessingAction/postcss.config.compressed.ts +31 -0
  172. package/ts/actions/StyleProcessingAction/postcss.config.expanded.ts +47 -0
  173. package/ts/actions/SvgPackagerAction/SvgPackagerAction.ts +187 -0
  174. package/ts/actions/SvgPackagerAction/index.ts +11 -0
  175. package/ts/actions/SvgReaderAction/SvgReaderAction.ts +77 -0
  176. package/ts/actions/SvgReaderAction/index.ts +11 -0
  177. package/ts/actions/SvgSpriteAction/SvgSpriteAction.ts +127 -0
  178. package/ts/actions/SvgSpriteAction/index.ts +11 -0
  179. package/ts/actions/SvgSpriteAction/svgsprite.config.ts +123 -0
  180. package/ts/actions/SvgToPngAction/SvgToPngAction.ts +113 -0
  181. package/ts/actions/SvgToPngAction/index.ts +11 -0
  182. package/ts/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts +117 -0
  183. package/ts/actions/TypeScriptCompilerAction/index.ts +11 -0
  184. package/ts/actions/VersionWriteAction/VersionWriteAction.ts +174 -0
  185. package/ts/actions/VersionWriteAction/index.ts +11 -0
  186. package/ts/actions/index.ts +0 -0
  187. package/ts/cli/ArgumentParser.ts +150 -0
  188. package/ts/cli/index.ts +1 -0
  189. package/ts/cli.ts +56 -0
  190. package/ts/core/abstract/AbstractProcess.ts +109 -0
  191. package/ts/core/abstract/AbstractSingleton.ts +46 -0
  192. package/ts/core/abstract/AbstractValidator.ts +167 -0
  193. package/ts/core/abstract/index.ts +0 -0
  194. package/ts/core/config/ConfigLoader.ts +141 -0
  195. package/ts/core/config/ConfigStore copy.ts +201 -0
  196. package/ts/core/config/ConfigStore.ts +157 -0
  197. package/ts/core/config/defaultConfig.ts +154 -0
  198. package/ts/core/config/index.ts +0 -0
  199. package/ts/core/index.ts +34 -0
  200. package/ts/core/pipeline/Action.ts +101 -0
  201. package/ts/core/pipeline/ActionRegistry.ts +216 -0
  202. package/ts/core/pipeline/Pipeline.ts +121 -0
  203. package/ts/core/pipeline/PipelineManager.ts +170 -0
  204. package/ts/core/pipeline/Stage.ts +131 -0
  205. package/ts/core/pipeline/Step.ts +96 -0
  206. package/ts/core/pipeline/index.ts +0 -0
  207. package/ts/core/validation/ActionValidator.ts +97 -0
  208. package/ts/core/validation/ConfigValidator.ts +103 -0
  209. package/ts/core/validation/OptionsValidator.ts +179 -0
  210. package/ts/core/validation/StageValidator.ts +175 -0
  211. package/ts/core/validation/StepValidator.ts +203 -0
  212. package/ts/core/validation/index.ts +0 -0
  213. package/ts/index.ts +26 -0
  214. package/ts/interface/ActionInterface.ts +70 -0
  215. package/ts/interface/ActionPlugin.ts +14 -0
  216. package/ts/interface/ConfigInterface.ts +55 -0
  217. package/ts/interface/File.ts +24 -0
  218. package/ts/interface/LiveOptionsInterface.ts +46 -0
  219. package/ts/interface/MetadataInterface.ts +105 -0
  220. package/ts/interface/OptionsInterface.ts +58 -0
  221. package/ts/interface/PackageJson.ts +171 -0
  222. package/ts/interface/PipelineOptionsInterface.ts +74 -0
  223. package/ts/interface/SVG.ts +84 -0
  224. package/ts/interface/StageInterface.ts +96 -0
  225. package/ts/interface/StepInterface.ts +83 -0
  226. package/ts/interface/StepOptionsInterface.ts +57 -0
  227. package/ts/interface/index.ts +9 -0
  228. package/ts/kist.ts +161 -0
  229. package/ts/live/LiveServer.ts +311 -0
  230. package/ts/live/LiveWatcher.ts +150 -0
  231. package/ts/live/index.ts +11 -0
  232. package/ts/logger/Logger.ts +187 -0
  233. package/ts/logger/LoggerStyles.ts +28 -0
  234. package/ts/logger/index.ts +0 -0
  235. package/ts/types/ActionOptionsType.ts +10 -0
  236. package/ts/types/index.ts +3 -0
  237. package/index.js +0 -3
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Import
4
+ // ============================================================================
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ActionRegistry = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const CoreActions_1 = require("../../actions/CoreActions");
10
+ const AbstractProcess_1 = require("../abstract/AbstractProcess");
11
+ // ============================================================================
12
+ // Class
13
+ // ============================================================================
14
+ /**
15
+ * ActionRegistry is a singleton registry for step actions, mapping action
16
+ * names to their corresponding classes. This registry allows dynamic
17
+ * resolution of step actions within the pipeline and supports custom
18
+ * developer integrations.
19
+ */
20
+ class ActionRegistry extends AbstractProcess_1.AbstractProcess {
21
+ // Constructor
22
+ // ========================================================================
23
+ /**
24
+ * Constructs an ActionRegistry instance and automatically registers core
25
+ * actions. The constructor is private to enforce the singleton pattern.
26
+ */
27
+ constructor() {
28
+ // Initialize logging through AbstractProcess
29
+ super();
30
+ this.registry = new Map();
31
+ // Automatically register core actions
32
+ this.registerCoreActions();
33
+ this.discoverPlugins();
34
+ this.logInfo("ActionRegistry initialized.");
35
+ }
36
+ // Singleton Methods
37
+ // ========================================================================
38
+ /**
39
+ * Initializes the singleton instance of ActionRegistry.
40
+ * Should only be called once during application startup.
41
+ *
42
+ * @throws Error if the registry has already been initialized.
43
+ */
44
+ static initialize() {
45
+ if (ActionRegistry.instance) {
46
+ throw new Error("ActionRegistry has already been initialized.");
47
+ }
48
+ ActionRegistry.instance = new ActionRegistry();
49
+ }
50
+ /**
51
+ * Retrieves the singleton instance of ActionRegistry, initializing it if
52
+ * necessary.
53
+ *
54
+ * @returns The ActionRegistry instance.
55
+ */
56
+ static getInstance() {
57
+ if (!ActionRegistry.instance) {
58
+ ActionRegistry.instance = new ActionRegistry();
59
+ }
60
+ return ActionRegistry.instance;
61
+ }
62
+ /**
63
+ * Resets the singleton instance of ActionRegistry.
64
+ * This is useful for testing or resetting the registry state during
65
+ * runtime.
66
+ */
67
+ static resetInstance() {
68
+ ActionRegistry.instance = null;
69
+ }
70
+ // Instance Methods
71
+ // ========================================================================
72
+ /**
73
+ * Registers a new action in the registry.
74
+ *
75
+ * @param actionClass - The class implementing `ActionInterface`.
76
+ * @throws Error if the action name is already registered or missing.
77
+ */
78
+ registerAction(actionClass) {
79
+ const actionInstance = new actionClass();
80
+ const name = actionInstance.name;
81
+ if (!name || typeof name !== "string") {
82
+ throw new Error(`[ActionRegistry] Action class must have a valid 'name' property.`);
83
+ }
84
+ if (this.registry.has(name)) {
85
+ throw new Error(`[ActionRegistry] Action "${name}" is already registered.`);
86
+ }
87
+ this.registry.set(name, actionClass);
88
+ this.logInfo(`Action "${name}" registered successfully.`);
89
+ }
90
+ /**
91
+ * Retrieves a step action class from the registry.
92
+ * This method looks up an action by name and returns the corresponding
93
+ * class that implements the ActionInterface.
94
+ *
95
+ * @param name - The name of the action to retrieve.
96
+ * @returns The action class constructor if found, or undefined if no such
97
+ * action is registered.
98
+ */
99
+ getAction(name) {
100
+ // Validate the input name
101
+ if (!name || typeof name !== "string") {
102
+ this.logWarn(`Invalid action name requested: "${name}".`);
103
+ return undefined;
104
+ }
105
+ // Retrieve the action from the registry
106
+ const action = this.registry.get(name);
107
+ // Log a warning if the action is not found
108
+ if (!action) {
109
+ this.logWarn(`Action "${name}" not found in the registry.`);
110
+ }
111
+ else {
112
+ this.logDebug(`Retrieved action "${name}" from the registry.`);
113
+ }
114
+ return action;
115
+ }
116
+ /**
117
+ * Lists all registered step actions.
118
+ * Provides a utility to view currently registered actions, useful for
119
+ * debugging and validation.
120
+ *
121
+ * @returns An array of registered action names.
122
+ */
123
+ listRegisteredActions() {
124
+ this.logDebug("Listing all registered actions.");
125
+ return Array.from(this.registry.keys());
126
+ }
127
+ /**
128
+ * Pre-registers core actions that are included with the pipeline by
129
+ * default. Developers can extend this by registering additional custom
130
+ * actions as needed.
131
+ */
132
+ registerCoreActions() {
133
+ Object.values(CoreActions_1.coreActions).forEach((actionClass) => {
134
+ this.registerAction(actionClass);
135
+ });
136
+ this.logInfo("Core actions registered successfully.");
137
+ }
138
+ discoverPlugins() {
139
+ this.logInfo("Discovering external plugins...");
140
+ const nodeModulesPath = (0, path_1.join)(process.cwd(), "node_modules");
141
+ const pluginPrefix = "@kist/plugin-";
142
+ try {
143
+ const directories = (0, fs_1.readdirSync)(nodeModulesPath, {
144
+ withFileTypes: true,
145
+ });
146
+ for (const dir of directories) {
147
+ if (dir.isDirectory() && dir.name.startsWith(pluginPrefix)) {
148
+ const pluginPath = (0, path_1.join)(nodeModulesPath, dir.name);
149
+ const plugin = require(pluginPath).default;
150
+ if (plugin &&
151
+ typeof plugin.registerActions === "function") {
152
+ const actions = plugin.registerActions();
153
+ for (const [name, actionClass] of Object.entries(actions)) {
154
+ this.registerAction(actionClass);
155
+ }
156
+ }
157
+ }
158
+ }
159
+ this.logInfo("Plugins loaded successfully.");
160
+ }
161
+ catch (error) {
162
+ this.logError("Failed to discover plugins.", error);
163
+ }
164
+ }
165
+ /**
166
+ * Clears all registered actions in the registry.
167
+ * Useful for testing or resetting the pipeline.
168
+ */
169
+ clearRegistry() {
170
+ this.registry.clear();
171
+ this.logInfo("Registry cleared.");
172
+ }
173
+ }
174
+ exports.ActionRegistry = ActionRegistry;
175
+ // Parameters
176
+ // ========================================================================
177
+ /**
178
+ * Singleton instance
179
+ */
180
+ ActionRegistry.instance = null;
@@ -0,0 +1,42 @@
1
+ import { ConfigInterface } from "../../interface/ConfigInterface";
2
+ import { AbstractProcess } from "../abstract/AbstractProcess";
3
+ /**
4
+ * Represents the pipeline of stages to be executed.
5
+ * This class manages the execution flow of stages, including parallel
6
+ * execution, dependency handling, and applying global options for consistent
7
+ * pipeline behavior.
8
+ */
9
+ export declare class Pipeline extends AbstractProcess {
10
+ private config;
11
+ /**
12
+ * List of stages to be executed in the pipeline.
13
+ */
14
+ private stages;
15
+ /**
16
+ * Global options that apply across the entire pipeline.
17
+ */
18
+ private options?;
19
+ /**
20
+ * Constructs a new Pipeline instance with the given configuration.
21
+ * Initializes stages and applies global options for execution control.
22
+ *
23
+ * @param config - The configuration object defining the stages, steps,
24
+ * and global options for the pipeline.
25
+ */
26
+ constructor(config: ConfigInterface);
27
+ /**
28
+ * Runs the pipeline, executing stages based on their dependencies.
29
+ * Stages are run in parallel by default, but their execution respects
30
+ * defined dependencies. Applies global options for logging, error
31
+ * handling, and execution control.
32
+ */
33
+ run(): Promise<void>;
34
+ /**
35
+ * Runs the stage promises with concurrency control based on global
36
+ * options. Limits the number of parallel running stages if
37
+ * maxConcurrentStages is set in global options.
38
+ * @param stagePromises - An array of promises representing stage
39
+ * executions.
40
+ */
41
+ private runWithConcurrencyControl;
42
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Import
4
+ // ============================================================================
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Pipeline = void 0;
16
+ const AbstractProcess_1 = require("../abstract/AbstractProcess");
17
+ const Stage_1 = require("./Stage");
18
+ // ============================================================================
19
+ // Class
20
+ // ============================================================================
21
+ /**
22
+ * Represents the pipeline of stages to be executed.
23
+ * This class manages the execution flow of stages, including parallel
24
+ * execution, dependency handling, and applying global options for consistent
25
+ * pipeline behavior.
26
+ */
27
+ class Pipeline extends AbstractProcess_1.AbstractProcess {
28
+ // Constructor
29
+ // ========================================================================
30
+ /**
31
+ * Constructs a new Pipeline instance with the given configuration.
32
+ * Initializes stages and applies global options for execution control.
33
+ *
34
+ * @param config - The configuration object defining the stages, steps,
35
+ * and global options for the pipeline.
36
+ */
37
+ constructor(config) {
38
+ super();
39
+ this.config = config;
40
+ this.stages = config.stages.map((stage) => new Stage_1.Stage(stage));
41
+ this.options = config.options;
42
+ this.logInfo("Pipeline instance created.");
43
+ }
44
+ // Methods
45
+ // ========================================================================
46
+ /**
47
+ * Runs the pipeline, executing stages based on their dependencies.
48
+ * Stages are run in parallel by default, but their execution respects
49
+ * defined dependencies. Applies global options for logging, error
50
+ * handling, and execution control.
51
+ */
52
+ run() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ var _a;
55
+ this.logInfo("Starting pipeline execution...");
56
+ // Track stages that have been completed
57
+ const completedStages = new Set();
58
+ // Run stages with dependency management and parallel execution control
59
+ try {
60
+ this.logDebug("Pipeline execution started with debug logging.");
61
+ // Execute all stages with concurrency control
62
+ const stagePromises = this.stages.map((stage) => stage.execute(completedStages));
63
+ yield this.runWithConcurrencyControl(stagePromises);
64
+ this.logInfo("Pipeline execution completed successfully.");
65
+ }
66
+ catch (error) {
67
+ this.logError("Pipeline execution failed:", error);
68
+ // Halt pipeline if configured to do so on failure
69
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.haltOnFailure) !== false) {
70
+ this.logError("Halting pipeline due to failure.");
71
+ process.exit(1);
72
+ }
73
+ else {
74
+ this.logWarn("Continuing pipeline execution despite errors.");
75
+ }
76
+ }
77
+ });
78
+ }
79
+ /**
80
+ * Runs the stage promises with concurrency control based on global
81
+ * options. Limits the number of parallel running stages if
82
+ * maxConcurrentStages is set in global options.
83
+ * @param stagePromises - An array of promises representing stage
84
+ * executions.
85
+ */
86
+ runWithConcurrencyControl(stagePromises) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ var _a;
89
+ const maxConcurrentStages = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.maxConcurrentStages) || stagePromises.length;
90
+ // Process stages with a concurrency limit
91
+ const executingStages = new Set();
92
+ for (const stagePromise of stagePromises) {
93
+ executingStages.add(stagePromise);
94
+ // Ensure stages are removed from the set once complete
95
+ stagePromise.finally(() => executingStages.delete(stagePromise));
96
+ // Enforce concurrency limit
97
+ if (executingStages.size >= maxConcurrentStages) {
98
+ // Wait until at least one stage completes
99
+ yield Promise.race(executingStages);
100
+ }
101
+ }
102
+ // Wait for all remaining stages to complete
103
+ yield Promise.all(executingStages);
104
+ });
105
+ }
106
+ }
107
+ exports.Pipeline = Pipeline;
@@ -0,0 +1,55 @@
1
+ import { LiveServer } from "../../live/LiveServer";
2
+ import { AbstractProcess } from "../abstract/AbstractProcess";
3
+ /**
4
+ * Manages the lifecycle of the pipeline process and integrates with the
5
+ * LiveServer for client notifications upon pipeline events.
6
+ */
7
+ export declare class PipelineManager extends AbstractProcess {
8
+ private liveServer?;
9
+ /**
10
+ * The current instance of the pipeline process.
11
+ */
12
+ private pipelineProcess;
13
+ /**
14
+ * Flag to prevent overlapping restarts.
15
+ */
16
+ private isRestarting;
17
+ /**
18
+ * Initializes the PipelineManager with a LiveServer instance.
19
+ *
20
+ * @param liveServer - The LiveServer instance to notify when the
21
+ * pipeline restarts.
22
+ */
23
+ constructor(liveServer?: LiveServer | undefined);
24
+ /**
25
+ * Runs the pipeline using the configuration from the `ConfigStore`.
26
+ * This method executes the pipeline stages directly, bypassing the CLI.
27
+ */
28
+ runPipeline(): Promise<void>;
29
+ /**
30
+ * Restarts the pipeline process, stopping any currently running process.
31
+ * Notifies connected clients via the LiveServer after restarting.
32
+ */
33
+ restartPipeline(): void;
34
+ /**
35
+ * Attaches event listeners to the pipeline process for logging and
36
+ * notification purposes.
37
+ */
38
+ private attachProcessListeners;
39
+ /**
40
+ * Stops the currently running pipeline process, if any.
41
+ * Gracefully kills the process and handles cleanup.
42
+ */
43
+ stopPipeline(): void;
44
+ /**
45
+ * Checks if the pipeline process is currently running.
46
+ * @returns True if the pipeline process is running, false otherwise.
47
+ */
48
+ isPipelineRunning(): boolean;
49
+ /**
50
+ * Restarts the pipeline with a delay, useful for throttling restarts when
51
+ * changes occur rapidly.
52
+ * @param delay - The delay in milliseconds before restarting the pipeline.
53
+ */
54
+ restartPipelineWithDelay(delay?: number): void;
55
+ }
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Import
4
+ // ============================================================================
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.PipelineManager = void 0;
19
+ const child_process_1 = require("child_process");
20
+ const path_1 = __importDefault(require("path"));
21
+ const AbstractProcess_1 = require("../abstract/AbstractProcess");
22
+ const ConfigStore_1 = require("../config/ConfigStore");
23
+ const Pipeline_1 = require("./Pipeline");
24
+ // ============================================================================
25
+ // Class
26
+ // ============================================================================
27
+ /**
28
+ * Manages the lifecycle of the pipeline process and integrates with the
29
+ * LiveServer for client notifications upon pipeline events.
30
+ */
31
+ class PipelineManager extends AbstractProcess_1.AbstractProcess {
32
+ // Constructor
33
+ // ========================================================================
34
+ /**
35
+ * Initializes the PipelineManager with a LiveServer instance.
36
+ *
37
+ * @param liveServer - The LiveServer instance to notify when the
38
+ * pipeline restarts.
39
+ */
40
+ constructor(liveServer) {
41
+ super();
42
+ this.liveServer = liveServer;
43
+ // Parameters
44
+ // ========================================================================
45
+ /**
46
+ * The current instance of the pipeline process.
47
+ */
48
+ this.pipelineProcess = null;
49
+ /**
50
+ * Flag to prevent overlapping restarts.
51
+ */
52
+ this.isRestarting = false;
53
+ this.logInfo("PipelineManager initialized.");
54
+ }
55
+ // Methods
56
+ // ========================================================================
57
+ /**
58
+ * Runs the pipeline using the configuration from the `ConfigStore`.
59
+ * This method executes the pipeline stages directly, bypassing the CLI.
60
+ */
61
+ runPipeline() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ var _a;
64
+ const config = ConfigStore_1.ConfigStore.getInstance().getConfig();
65
+ if (!config.stages || !Array.isArray(config.stages)) {
66
+ throw new Error("Invalid configuration: 'stages' must be an array.");
67
+ }
68
+ this.logInfo("Initializing pipeline...");
69
+ const pipeline = new Pipeline_1.Pipeline(config);
70
+ try {
71
+ yield pipeline.run();
72
+ this.logInfo("Pipeline execution finished successfully.");
73
+ (_a = this.liveServer) === null || _a === void 0 ? void 0 : _a.reloadClients();
74
+ }
75
+ catch (error) {
76
+ this.logError("Error during pipeline execution.", error);
77
+ throw error;
78
+ }
79
+ });
80
+ }
81
+ /**
82
+ * Restarts the pipeline process, stopping any currently running process.
83
+ * Notifies connected clients via the LiveServer after restarting.
84
+ */
85
+ restartPipeline() {
86
+ if (this.isRestarting) {
87
+ this.logWarn("Pipeline restart already in progress. Skipping...");
88
+ return;
89
+ }
90
+ this.isRestarting = true;
91
+ if (this.pipelineProcess) {
92
+ this.logInfo("Stopping current pipeline process...");
93
+ this.stopPipeline();
94
+ }
95
+ this.logInfo("Starting pipeline...");
96
+ const scriptPath = path_1.default.resolve(process.cwd(), "dist/js/cli.js");
97
+ this.pipelineProcess = (0, child_process_1.spawn)("node", [scriptPath], {
98
+ stdio: "inherit",
99
+ });
100
+ this.attachProcessListeners();
101
+ this.isRestarting = false;
102
+ }
103
+ /**
104
+ * Attaches event listeners to the pipeline process for logging and
105
+ * notification purposes.
106
+ */
107
+ attachProcessListeners() {
108
+ if (!this.pipelineProcess)
109
+ return;
110
+ this.pipelineProcess.on("close", (code) => {
111
+ var _a;
112
+ if (code !== 0) {
113
+ this.logError(`Pipeline process exited with code ${code}`);
114
+ }
115
+ else {
116
+ this.logInfo("Pipeline process exited successfully.");
117
+ }
118
+ (_a = this.liveServer) === null || _a === void 0 ? void 0 : _a.reloadClients();
119
+ });
120
+ this.pipelineProcess.on("error", (error) => {
121
+ this.logError("Error starting pipeline process.", error);
122
+ });
123
+ this.pipelineProcess.on("exit", (code, signal) => {
124
+ if (signal) {
125
+ this.logWarn(`Pipeline process was terminated with signal: ${signal}`);
126
+ }
127
+ else {
128
+ this.logInfo(`Pipeline process exited with code: ${code}`);
129
+ }
130
+ });
131
+ }
132
+ /**
133
+ * Stops the currently running pipeline process, if any.
134
+ * Gracefully kills the process and handles cleanup.
135
+ */
136
+ stopPipeline() {
137
+ if (this.pipelineProcess) {
138
+ this.logInfo("Stopping pipeline process...");
139
+ this.pipelineProcess.kill("SIGTERM");
140
+ this.pipelineProcess = null;
141
+ this.logInfo("Pipeline process stopped.");
142
+ }
143
+ else {
144
+ this.logWarn("No pipeline process is currently running.");
145
+ }
146
+ }
147
+ /**
148
+ * Checks if the pipeline process is currently running.
149
+ * @returns True if the pipeline process is running, false otherwise.
150
+ */
151
+ isPipelineRunning() {
152
+ return this.pipelineProcess !== null && !this.pipelineProcess.killed;
153
+ }
154
+ /**
155
+ * Restarts the pipeline with a delay, useful for throttling restarts when
156
+ * changes occur rapidly.
157
+ * @param delay - The delay in milliseconds before restarting the pipeline.
158
+ */
159
+ restartPipelineWithDelay(delay = 1000) {
160
+ this.logInfo(`Delaying pipeline restart by ${delay} milliseconds...`);
161
+ setTimeout(() => this.restartPipeline(), delay);
162
+ }
163
+ }
164
+ exports.PipelineManager = PipelineManager;
@@ -0,0 +1,45 @@
1
+ import { StageInterface } from "../../interface/StageInterface";
2
+ import { AbstractProcess } from "../abstract/AbstractProcess";
3
+ /**
4
+ * Represents a stage in the pipeline, encapsulating its execution logic and
5
+ * dependencies. Each stage consists of multiple steps that are executed
6
+ * consecutively, and stages can have dependencies on other stages which are
7
+ * managed before execution.
8
+ */
9
+ export declare class Stage extends AbstractProcess {
10
+ private name;
11
+ private steps;
12
+ private dependsOn?;
13
+ /**
14
+ * Constructs a Stage instance with the given stage definition.
15
+ * @param stage - The stage definition containing name, steps, and
16
+ * dependencies.
17
+ */
18
+ constructor(stage: StageInterface);
19
+ /**
20
+ * Executes the stage by running its steps consecutively.
21
+ * Manages dependencies by waiting for dependent stages to complete
22
+ * before execution.
23
+ * @param completedStages - A set of completed stage names used for
24
+ * dependency tracking.
25
+ * @throws Error if any step within the stage fails.
26
+ */
27
+ execute(completedStages: Set<string>): Promise<void>;
28
+ /**
29
+ * Resolves dependencies by ensuring all required stages have completed.
30
+ * @param completedStages - A set of completed stage names used for
31
+ * dependency tracking.
32
+ * @returns A promise that resolves once all dependencies are met.
33
+ */
34
+ private resolveDependencies;
35
+ /**
36
+ * Waits for a specified stage to complete by monitoring the completed
37
+ * stages set.
38
+ * @param stageName - The name of the stage to wait for.
39
+ * @param completedStages - A set of completed stage names used for
40
+ * dependency tracking.
41
+ * @returns A promise that resolves when the specified stage is marked
42
+ * as completed.
43
+ */
44
+ private waitForStageCompletion;
45
+ }