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