| 2 | import {spawn} from 'child_process'; |
| 3 | |
| 4 | export async function exitServer() { |
| 5 | const spinner = p.spinner(); |
| 6 | spinner.start('Stopping AI server...'); |
| 7 | // Spawn the server process detached from the parent |
| 8 | const serverProcess = spawn('npx', ['kill-port', '9000'], { |
| 9 | // Detach the process so it runs independently |
| 10 | detached: true, |
| 11 | // Pipe stdout/stderr to files or ignore them |
| 12 | stdio: 'ignore', |
| 13 | shell: process.platform === 'win32', |
| 14 | }); |
| 15 | |
| 16 | // Unref the process so it won't keep the parent alive |
| 17 | serverProcess.unref(); |
| 18 | spinner.stop('AI server stopped.'); |
| 19 | } |