(name, command, args, options = {})
| 243 | let shuttingDown = false; |
| 244 | |
| 245 | function spawnService(name, command, args, options = {}) { |
| 246 | const proc = spawn( |
| 247 | resolveWindowsCommand(command), |
| 248 | args, |
| 249 | getProcessTreeSpawnOptions({ |
| 250 | stdio: ["ignore", "pipe", "pipe"], |
| 251 | env: { ...process.env, ...options.env }, |
| 252 | cwd: options.cwd, |
| 253 | }), |
| 254 | ); |
| 255 | |
| 256 | const color = options.color || c.reset; |
| 257 | |
| 258 | proc.stdout.on("data", (data) => { |
| 259 | data |
| 260 | .toString() |
| 261 | .split("\n") |
| 262 | .filter(Boolean) |
| 263 | .forEach((line) => logService(name, line.trim(), color)); |
| 264 | }); |
| 265 | |
| 266 | proc.stderr.on("data", (data) => { |
| 267 | data |
| 268 | .toString() |
| 269 | .split("\n") |
| 270 | .filter(Boolean) |
| 271 | .forEach((line) => logService(name, line.trim(), c.yellow)); |
| 272 | }); |
| 273 | |
| 274 | proc.on("error", (error) => { |
| 275 | logError(`${name} failed to start: ${error.message}`); |
| 276 | }); |
| 277 | |
| 278 | proc.on("exit", (code) => { |
| 279 | if (code !== 0 && code !== null && !shuttingDown) { |
| 280 | logService(name, `Exited with code ${code}`, c.red); |
| 281 | } |
| 282 | processes.delete(name); |
| 283 | }); |
| 284 | |
| 285 | processes.set(name, proc); |
| 286 | return proc; |
| 287 | } |
| 288 | |
| 289 | async function waitForService(name, url, timeoutMs = 30000) { |
| 290 | const start = Date.now(); |
no test coverage detected