-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-admin.js
More file actions
47 lines (38 loc) · 1.48 KB
/
start-admin.js
File metadata and controls
47 lines (38 loc) · 1.48 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
const { spawn, execSync } = require('child_process');
const net = require('net');
const PORT = 3005;
// Check if port is taken (by trying to connect)
const isPortTaken = (port) => new Promise((resolve) => {
const socket = new net.Socket();
socket.setTimeout(400);
socket.on('connect', () => { socket.destroy(); resolve(true); });
socket.on('timeout', () => { socket.destroy(); resolve(false); });
socket.on('error', () => { socket.destroy(); resolve(false); });
socket.connect(port, '127.0.0.1');
});
(async () => {
if (await isPortTaken(PORT)) {
console.log(`⚠️ Port ${PORT} is already in use. Assuming Admin Panel is running.`);
console.log('✅ Skipping Admin Panel start.');
process.exit(0);
}
console.log(`🚀 Starting Admin Panel on port ${PORT}...`);
// Navigate to admin directory
const adminDir = __dirname; // This script should be in admin/ or we adjust path.
// Actually, let's put it in root for consistency with other start scripts.
// If in root, admin dir is ./admin
const cwd = process.cwd().endsWith('admin') ? process.cwd() : 'admin';
const child = spawn('pnpm', ['run', 'dev'], {
stdio: 'inherit',
shell: true,
cwd: cwd,
env: { ...process.env }
});
child.on('error', (error) => {
console.error('Failed to start Admin Panel:', error);
process.exit(1);
});
child.on('exit', (code) => {
process.exit(code || 0);
});
})();