* Fallback to running the CLI using Node.js
()
| 172 | * Fallback to running the CLI using Node.js |
| 173 | */ |
| 174 | function runCliFallback() { |
| 175 | const cliPath = findCliScript(); |
| 176 | |
| 177 | if (!cliPath) { |
| 178 | console.log(`${colors.red}Error: Could not find any SPARC2 CLI script.${colors.reset}`); |
| 179 | console.log(`${colors.yellow}This could be due to an incomplete installation or build.${colors.reset}`); |
| 180 | console.log(`${colors.yellow}Try running 'npm run build' in the SPARC2 directory.${colors.reset}`); |
| 181 | process.exit(1); |
| 182 | } |
| 183 | |
| 184 | console.log(`${colors.green}Found CLI at: ${cliPath}${colors.reset}`); |
| 185 | |
| 186 | // Run the CLI using Node |
| 187 | const nodeArgs = [cliPath, ...process.argv.slice(2)]; |
| 188 | console.log(`${colors.blue}Running: node ${nodeArgs.join(' ')}${colors.reset}`); |
| 189 | |
| 190 | // Spawn the Node process |
| 191 | const nodeProcess = spawn('node', nodeArgs, { |
| 192 | stdio: 'inherit', |
| 193 | env: process.env |
| 194 | }); |
| 195 | |
| 196 | // Handle process exit |
| 197 | nodeProcess.on('exit', (code) => { |
| 198 | if (code !== 0) { |
| 199 | console.log(`${colors.red}CLI exited with code ${code}${colors.reset}`); |
| 200 | process.exit(code); |
| 201 | } |
| 202 | }); |
| 203 | |
| 204 | // Forward signals to the child process |
| 205 | ['SIGINT', 'SIGTERM'].forEach(signal => { |
| 206 | process.on(signal, () => { |
| 207 | nodeProcess.kill(signal); |
| 208 | }); |
| 209 | }); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Run a simplified version of the CLI directly |
no test coverage detected