-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_backend.cjs
More file actions
66 lines (54 loc) · 1.76 KB
/
start_backend.cjs
File metadata and controls
66 lines (54 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
/**
* Start backend server script
* Works on Windows, Mac, and Linux
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const backendDir = path.join(__dirname, 'backend');
const scriptPath = path.join(backendDir, 'run_backend_simple.py');
// Check if script exists
if (!fs.existsSync(scriptPath)) {
console.error('ERROR: run_backend_simple.py not found!');
console.error(`Expected at: ${scriptPath}`);
process.exit(1);
}
// Determine Python command
// On Windows, prefer 'python' over 'py' to use the correct environment
// 'py' launcher may point to a different Python installation
// Prioritize Python 3.11+ for dedalus-labs compatibility
const isWin = process.platform === 'win32';
const pythonCommands = isWin ? ['python', 'py'] : ['python3.11', 'python3', 'python'];
let currentIndex = 0;
function tryStartPython() {
if (currentIndex >= pythonCommands.length) {
console.error('ERROR: Python not found!');
console.error('Please install Python and make sure it\'s in your PATH.');
process.exit(1);
}
const python = pythonCommands[currentIndex];
console.log(`[backend] Trying to start with: ${python}`);
const proc = spawn(python, ['run_backend_simple.py'], {
cwd: backendDir,
stdio: 'inherit',
shell: isWin
});
proc.on('error', (err) => {
if (err.code === 'ENOENT') {
// Python command not found, try next one
currentIndex++;
tryStartPython();
} else {
console.error(`[backend] Error: ${err.message}`);
process.exit(1);
}
});
proc.on('exit', (code) => {
if (code !== 0 && code !== null) {
console.error(`[backend] Process exited with code ${code}`);
process.exit(code);
}
});
}
tryStartPython();