import { spawn } from 'node:child_process'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { resolveGameCreatorAppConfigDir } from './game-creator-config-wizard.mjs'; const appRoot = path.resolve(fileURLToPath(new URL('..', import.meta.url))); const cliArguments = process.argv.slice(2); const hasConfigDir = cliArguments.some( (argument, index) => argument === '--config-dir' || (index > 0 && cliArguments[index - 1] === '--config-dir'), ); const runtimeConfigArguments = hasConfigDir ? [] : ['--config-dir', resolveGameCreatorAppConfigDir()]; const cargo = process.platform === 'win32' ? 'cargo.exe' : 'cargo'; const child = spawn( cargo, [ 'run', '--manifest-path', 'src-tauri/Cargo.toml', '--', ...runtimeConfigArguments, ...cliArguments, ], { cwd: appRoot, stdio: 'inherit', }, ); for (const signal of ['SIGINT', 'SIGTERM']) { process.on(signal, () => { child.kill(signal); }); } child.on('exit', (code, signal) => { if (signal) { process.exit(1); } process.exit(code ?? 0); });