This commit is contained in:
ChinhLee 2026-05-25 10:06:35 +08:00 committed by GitHub
commit 4dcdb43132
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 45 additions and 0 deletions

45
scripts/dev-backend.js Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env node
/**
* Cross-platform backend dev launcher.
* Tries launch commands in order: uv, python3, python, py
* so Windows users without uv can still run `npm run dev`.
*/
const { spawn } = require('child_process');
const path = require('path');
const backend_script = path.join(__dirname, '..', 'backend', 'run.py');
const candidates = [
['uv', ['run', 'python', backend_script]],
['python3', [backend_script]],
['python', [backend_script]],
['py', [backend_script]],
];
function try_next(index) {
if (index >= candidates.length) {
console.error('No suitable Python interpreter found. Install uv, python3, python, or py.');
process.exit(1);
}
const [cmd, args] = candidates[index];
console.log(`Trying: ${cmd} ${args.join(' ')}`);
const child = spawn(cmd, args, {
stdio: 'inherit',
shell: process.platform === 'win32',
});
child.on('error', () => {
try_next(index + 1);
});
child.on('exit', (code) => {
if (code !== 0) {
process.exit(code);
}
});
}
try_next(0);