cispacempt-v2 0.0.4 → 0.0.6

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +48 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "main": "src/index.js",
3
3
  "name": "cispacempt-v2",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "Fast CI engine for CodespaceMPT with script stages and file system hooks",
6
6
  "author": "argentidev",
7
7
  "license": "MIT",
package/src/index.js CHANGED
@@ -2,6 +2,7 @@ const path = require("path"),
2
2
  os = require("os"),
3
3
  fs = require("fs"),
4
4
  { spawn } = require("child_process"),
5
+ yaml = require("js-yaml"),
5
6
  getCPUUsageSnapshot = function () {
6
7
  const cpus = os.cpus();
7
8
  return cpus.map(cpu => ({ ...cpu.times }));
@@ -90,6 +91,7 @@ module.exports = {
90
91
 
91
92
  parse: async function (ciScript, repoName, fileSystem, tmp = true) {
92
93
  let errorIn = [];
94
+ let successIn = [];
93
95
  let finalResult = [];
94
96
  let timeTaken;
95
97
  let combinedExitCode = 0;
@@ -107,6 +109,49 @@ module.exports = {
107
109
  });
108
110
  };
109
111
 
112
+ const findFileInMap = function (fileSystem, searchFilePath) {
113
+ const pathParts = searchFilePath.split("/");
114
+ let currentMap = fileSystem;
115
+
116
+ for (let i = 0; i < pathParts.length; i++) {
117
+ const part = pathParts[i];
118
+
119
+ if (currentMap[part]) {
120
+ if (typeof currentMap[part] === "object") {
121
+ currentMap = currentMap[part];
122
+ } else {
123
+ return currentMap[part]; // Return the found file if it exists
124
+ }
125
+ } else {
126
+ return null; // Return null if not found at all
127
+ }
128
+ }
129
+
130
+ return null; // Return null if path doesn't exist
131
+ }
132
+
133
+ if (ciScript.include) {
134
+ for (const includePath of ciScript.include) {
135
+ const templateContent = findFileInMap(fileSystem, includePath);
136
+ if (!templateContent) {
137
+ console.warn(`Included file '${includePath}' not found`);
138
+ continue;
139
+ }
140
+
141
+ const includedYaml = yaml.load(templateContent);
142
+
143
+ // Merge included content
144
+ ciScript.stages = {
145
+ ...(includedYaml.stages || {}),
146
+ ...(ciScript.stages || {})
147
+ };
148
+ ciScript.env = {
149
+ ...(includedYaml.env || {}),
150
+ ...(ciScript.env || {}),
151
+ };
152
+ }
153
+ }
154
+
110
155
  for (const stage of stages) {
111
156
  extensionSystem.runPreExecution(stage.name); // <-- pre execution hook
112
157
 
@@ -176,6 +221,7 @@ module.exports = {
176
221
  !errorIn.includes(stage.name) ? errorIn.push(stage.name) : null;
177
222
  } else {
178
223
  output += `${result.stdout ? result.stdout : ''}\n`;
224
+ !successIn.includes(stage.name) ? successIn.push(stage.name) : null;
179
225
  }
180
226
 
181
227
  if (result.exitCode !== 0) {
@@ -189,6 +235,7 @@ module.exports = {
189
235
  }
190
236
  }
191
237
 
238
+ console.log(successIn, errorIn);
192
239
  const finalResultEndTime = Date.now();
193
240
  timeTaken = convertMsToSec(finalResultEndTime - startTime);
194
241
  const cpuEnd = getCPUUsageSnapshot();
@@ -206,6 +253,7 @@ module.exports = {
206
253
  arch: os.arch(),
207
254
  },
208
255
  errorIn: errorIn.length > 0 ? errorIn : null,
256
+ successIn: successIn.length > 0 ? successIn : null,
209
257
  };
210
258
 
211
259
  cleanUpAndRespond(tempDir);