(name, command, args, options = {})
| 222 | let shuttingDown = false; |
| 223 | |
| 224 | function spawnService(name, command, args, options = {}) { |
| 225 | const proc = spawn( |
| 226 | resolveWindowsCommand(command), |
| 227 | args, |
| 228 | getProcessTreeSpawnOptions({ |
| 229 | stdio: ["ignore", "pipe", "pipe"], |
| 230 | env: { ...process.env, ...options.env }, |
| 231 | cwd: options.cwd, |
| 232 | }), |
| 233 | ); |
| 234 | |
| 235 | const color = options.color || c.reset; |
| 236 | |
| 237 | proc.stdout.on("data", (data) => { |
| 238 | data |
| 239 | .toString() |
| 240 | .split("\n") |
| 241 | .filter(Boolean) |
| 242 | .forEach((line) => logService(name, line.trim(), color)); |
| 243 | }); |
| 244 | |
| 245 | proc.stderr.on("data", (data) => { |
| 246 | data |
| 247 | .toString() |
| 248 | .split("\n") |
| 249 | .filter(Boolean) |
| 250 | .forEach((line) => logService(name, line.trim(), c.yellow)); |
| 251 | }); |
| 252 | |
| 253 | proc.on("error", (error) => { |
| 254 | logError(`${name} failed to start: ${error.message}`); |
| 255 | }); |
| 256 | |
| 257 | proc.on("exit", (code) => { |
| 258 | if (code !== 0 && code !== null && !shuttingDown) { |
| 259 | logService(name, `Exited with code ${code}`, c.red); |
| 260 | } |
| 261 | processes.delete(name); |
| 262 | }); |
| 263 | |
| 264 | processes.set(name, proc); |
| 265 | return proc; |
| 266 | } |
| 267 | |
| 268 | async function waitForService(name, url, timeoutMs = 30000) { |
| 269 | const start = Date.now(); |
no test coverage detected