-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-start.js
More file actions
112 lines (90 loc) Β· 2.87 KB
/
Copy pathdev-start.js
File metadata and controls
112 lines (90 loc) Β· 2.87 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
/**
* Development startup script that checks for experience configuration
* and runs Python setup if needed before starting the dev server
*/
import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const CONFIG_FILE = path.join(__dirname, 'src/config/experiences.json');
function checkConfigExists() {
try {
if (!fs.existsSync(CONFIG_FILE)) {
return false;
}
const data = fs.readFileSync(CONFIG_FILE, 'utf8');
const config = JSON.parse(data);
return config.allowedExperiences && config.allowedExperiences.length > 0;
} catch (error) {
return false;
}
}
function runPythonSetup() {
return new Promise((resolve, reject) => {
console.log('π§ No experience configuration found. Running Python setup...\n');
const pythonProcess = spawn('python', ['setup_experiences.py'], {
stdio: 'inherit',
shell: true
});
pythonProcess.on('close', (code) => {
if (code === 0) {
console.log('\nβ
Python setup completed successfully');
resolve();
} else {
console.log(`\nβ Python setup failed with code ${code}`);
reject(new Error(`Python setup failed with code ${code}`));
}
});
pythonProcess.on('error', (error) => {
console.error('β Error running Python setup:', error);
reject(error);
});
});
}
function startDevServer() {
console.log('π Starting Node.js development server...\n');
const devProcess = spawn('npx', ['tsx', 'watch', 'src/index.ts'], {
stdio: 'inherit',
shell: true
});
devProcess.on('close', (code) => {
console.log(`\nπ Development server stopped with code ${code}`);
});
devProcess.on('error', (error) => {
console.error('β Error starting development server:', error);
});
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\nπ Shutting down development server...');
devProcess.kill('SIGINT');
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\nπ Shutting down development server...');
devProcess.kill('SIGTERM');
process.exit(0);
});
}
async function main() {
try {
console.log('π Checking experience configuration...');
if (!checkConfigExists()) {
await runPythonSetup();
// Verify config was created
if (!checkConfigExists()) {
console.error('β Configuration still not found after setup. Please check the setup process.');
process.exit(1);
}
} else {
console.log('β
Experience configuration found');
}
startDevServer();
} catch (error) {
console.error('β Failed to start development environment:', error);
process.exit(1);
}
}
main();