scripts-orchestrator 2.7.0 → 2.7.1

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/README.md CHANGED
@@ -31,6 +31,8 @@ npm install --save-dev scripts-orchestrator
31
31
  - **Retry Mechanism**: Configurable retry attempts for failed commands
32
32
  - **Process Management**: Proper cleanup of background processes
33
33
  - **Health Checks**: Verifies service availability before proceeding
34
+ - **Environment Variables**: Pass custom environment variables to commands
35
+ - **Optional Phases**: Mark phases as optional and run them selectively
34
36
  - **Comprehensive Logging**: Detailed logging of command execution and results
35
37
 
36
38
  ## Configuration
@@ -45,6 +47,10 @@ Create a configuration file (default: `scripts-orchestrator.config.js`) that def
45
47
  attempts: 1, // Number of retry attempts
46
48
  dependencies: [], // Array of dependent commands
47
49
  background: false, // Whether to run in background
50
+ env: { // Optional environment variables
51
+ PORT: 3000,
52
+ NODE_ENV: 'production'
53
+ },
48
54
  kill_command: 'kill_storybook', // Optional kill command to kill the process
49
55
  health_check: { // Health check configuration
50
56
  url: 'http://localhost:port',
@@ -155,6 +161,52 @@ export default {
155
161
  };
156
162
  ```
157
163
 
164
+ ### Using Environment Variables
165
+
166
+ You can pass custom environment variables to commands using the `env` property. This is useful for configuring ports, API endpoints, or any environment-specific settings:
167
+
168
+ ```javascript
169
+ export default {
170
+ phases: [
171
+ {
172
+ name: 'playwright',
173
+ parallel: [
174
+ {
175
+ command: 'playwright_ci',
176
+ description: 'Run Playwright tests',
177
+ env: {
178
+ PLAYWRIGHT_PORT: 5173,
179
+ API_URL: 'http://localhost:3000',
180
+ TEST_ENV: 'ci'
181
+ },
182
+ status: 'enabled',
183
+ attempts: 1,
184
+ dependencies: [
185
+ {
186
+ command: 'dev',
187
+ background: true,
188
+ env: {
189
+ PORT: 5173
190
+ },
191
+ health_check: {
192
+ url: 'http://localhost:5173',
193
+ max_attempts: 20,
194
+ interval: 2000
195
+ }
196
+ }
197
+ ]
198
+ }
199
+ ]
200
+ }
201
+ ]
202
+ };
203
+ ```
204
+
205
+ The command will run with the environment variables set, equivalent to:
206
+ ```bash
207
+ PLAYWRIGHT_PORT=5173 API_URL=http://localhost:3000 TEST_ENV=ci npm run playwright_ci
208
+ ```
209
+
158
210
  See more examples [here](./docs/samples.md)
159
211
 
160
212
  ## Command Types
@@ -62,6 +62,7 @@ export class Orchestrator {
62
62
  process_tracking = false,
63
63
  health_check,
64
64
  kill_command,
65
+ env,
65
66
  } = commandConfig;
66
67
 
67
68
  const startTime = Date.now();
@@ -162,6 +163,7 @@ export class Orchestrator {
162
163
  healthCheck: health_check,
163
164
  kill_command,
164
165
  isRetry: attempt > 1,
166
+ env,
165
167
  });
166
168
  commandOutput = output;
167
169
  result = success;
@@ -37,7 +37,7 @@ export class ProcessManager {
37
37
  });
38
38
  }
39
39
 
40
- async runCommand({ cmd, logFile, background = false, healthCheck = null, kill_command = null, isRetry = false }) {
40
+ async runCommand({ cmd, logFile, background = false, healthCheck = null, kill_command = null, isRetry = false, env = null }) {
41
41
  const baseDir = this.logFolder ? path.resolve(this.logFolder) : process.cwd();
42
42
  const LOGS_DIR = path.join(baseDir, 'scripts-orchestrator-logs');
43
43
  // Use only the first word of the command for the log filename
@@ -62,10 +62,17 @@ export class ProcessManager {
62
62
  }
63
63
 
64
64
  return new Promise((resolve) => {
65
- this.logger.info(`Running: npm run ${cmd}`);
65
+ // Build command with environment variables if provided
66
+ let fullCommand = `npm run ${cmd}`;
67
+ if (env && Object.keys(env).length > 0) {
68
+ const envStr = Object.entries(env).map(([key, value]) => `${key}=${value}`).join(' ');
69
+ fullCommand = `${envStr} npm run ${cmd}`;
70
+ }
71
+
72
+ this.logger.info(`Running: ${fullCommand}`);
66
73
 
67
74
  // Create isolated environment for each process
68
- const isolatedEnv = this.createIsolatedEnvironment({ command: cmd });
75
+ const isolatedEnv = this.createIsolatedEnvironment({ command: cmd, env });
69
76
 
70
77
  const options = {
71
78
  shell: true,
@@ -80,8 +87,8 @@ export class ProcessManager {
80
87
  //this.logger.verbose(`Process options: ${JSON.stringify(options, null, 2)}`);
81
88
 
82
89
  try {
83
- this.logger.verbose(`Spawning process with command: npm run ${cmd}`);
84
- const processInstance = spawn('npm', ['run', cmd], options);
90
+ this.logger.verbose(`Spawning process with command: ${fullCommand}`);
91
+ const processInstance = spawn(fullCommand, [], options);
85
92
 
86
93
  processInstance.on('error', (error) => {
87
94
  this.logger.error(`Failed to start process: ${error.message}`);
@@ -235,7 +242,7 @@ export class ProcessManager {
235
242
  });
236
243
  }
237
244
 
238
- createIsolatedEnvironment({ command }) {
245
+ createIsolatedEnvironment({ command, env = null }) {
239
246
  // Create a deep copy to avoid any reference sharing
240
247
  const baseEnv = JSON.parse(JSON.stringify(process.env));
241
248
 
@@ -255,6 +262,13 @@ export class ProcessManager {
255
262
  npm_config_loglevel: 'error',
256
263
  };
257
264
 
265
+ // Merge custom environment variables if provided
266
+ if (env && typeof env === 'object') {
267
+ Object.entries(env).forEach(([key, value]) => {
268
+ isolatedEnv[key] = String(value);
269
+ });
270
+ }
271
+
258
272
  // Remove any potentially problematic environment variables
259
273
  delete isolatedEnv.npm_lifecycle_event;
260
274
  delete isolatedEnv.npm_lifecycle_script;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripts-orchestrator",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "A powerful script orchestrator for running parallel commands with dependency management, background processes, and health checks",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -99,6 +99,9 @@ export default {
99
99
  {
100
100
  command: 'playwright_ci',
101
101
  description: 'Run Playwright tests',
102
+ env: {
103
+ PLAYWRIGHT_PORT: 5173,
104
+ },
102
105
  status: 'enabled',
103
106
  attempts: 1, //Playwright internally retries in CI mode
104
107
  dependencies: [