Repository navigation
Expand file tree
/
Copy pathstart.js
More file actions
58 lines (49 loc) · 1.47 KB
/
Copy pathstart.js
File metadata and controls
58 lines (49 loc) · 1.47 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
#!/usr/bin/env node
// Don't run if inside Electron (main process will start backend)
if (process.versions.electron) {
console.log('Running inside Electron - backend will be started by main process');
process.exit(0);
}
const { spawn, execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const uiDistPath = path.join(__dirname, 'ui', 'dist');
const uiPath = path.join(__dirname, 'ui');
const backendPath = path.join(__dirname, 'backend');
// Check if UI is built
if (!fs.existsSync(uiDistPath)) {
console.log('UI not built. Building...');
try {
execSync('npm run build', { cwd: uiPath, stdio: 'inherit' });
console.log('UI build complete.');
} catch (error) {
console.error('Failed to build UI:', error.message);
process.exit(1);
}
}
// Start the backend server
console.log('Starting EasyCC server...');
const server = spawn('node', ['server.js'], {
cwd: backendPath,
stdio: 'inherit',
env: { ...process.env, NODE_ENV: 'production', PORT: '5010' }
});
server.on('error', (error) => {
console.error('Failed to start server:', error.message);
process.exit(1);
});
server.on('close', (code) => {
if (code !== 0) {
console.error(`Server exited with code ${code}`);
}
process.exit(code);
});
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\nShutting down...');
server.kill('SIGINT');
});
process.on('SIGTERM', () => {
console.log('\nShutting down...');
server.kill('SIGTERM');
});