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