-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
executable file
·122 lines (103 loc) · 3.1 KB
/
start.js
File metadata and controls
executable file
·122 lines (103 loc) · 3.1 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
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
/**
* Lockstep Chat - Cross-platform Startup Script
* Launches both server and client simultaneously
*/
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
// Colors for console output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
green: '\x1b[32m',
yellow: '\x1b[33m',
red: '\x1b[31m',
cyan: '\x1b[36m'
};
function log(message, color = colors.reset) {
console.log(`${color}${message}${colors.reset}`);
}
function logHeader() {
console.log();
log('================================================', colors.cyan);
log(' Lockstep Chat - Starting ', colors.cyan);
log('================================================', colors.cyan);
console.log();
}
function checkDependencies(dir, name) {
const modulesPath = path.join(dir, 'node_modules');
if (!fs.existsSync(modulesPath)) {
log(`Installing ${name} dependencies...`, colors.yellow);
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const install = spawn(npm, ['install'], {
cwd: dir,
stdio: 'inherit',
shell: true
});
return new Promise((resolve) => {
install.on('close', resolve);
});
}
return Promise.resolve();
}
async function startApp() {
logHeader();
// Check and install dependencies
const serverDir = path.join(__dirname, 'server');
const clientDir = path.join(__dirname, 'client');
log('Checking dependencies...', colors.yellow);
await checkDependencies(serverDir, 'server');
await checkDependencies(clientDir, 'client');
// Start server
log('Starting server on port 3001...', colors.green);
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const server = spawn(npm, ['start'], {
cwd: serverDir,
stdio: 'inherit',
shell: true
});
// Wait for server to start
await new Promise(resolve => setTimeout(resolve, 2000));
// Start client
log('Starting client on port 3000...', colors.green);
const client = spawn(npm, ['start'], {
cwd: clientDir,
stdio: 'inherit',
shell: true
});
console.log();
log('================================================', colors.green);
log(' Lockstep Chat is running! ', colors.green);
log('================================================', colors.green);
console.log();
log('Server: http://localhost:3001', colors.bright);
log('Client: http://localhost:3000', colors.bright);
console.log();
log('Press Ctrl+C to stop both server and client', colors.yellow);
console.log();
// Handle shutdown
const shutdown = () => {
console.log();
log('Shutting down Lockstep Chat...', colors.yellow);
server.kill();
client.kill();
process.exit(0);
};
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
// Keep the script running
server.on('exit', () => {
log('Server stopped', colors.red);
shutdown();
});
client.on('exit', () => {
log('Client stopped', colors.red);
shutdown();
});
}
// Run the startup script
startApp().catch(error => {
log(`Error: ${error.message}`, colors.red);
process.exit(1);
});