/** * Start script for ElevAIt * Runs both the Next.js server and the GitHub sync daemon */ const { spawn } = require('child_process'); const path = require('path'); console.log('🚀 Starting ElevAIt...'); // Start the GitHub sync daemon const daemonPath = path.join(__dirname, 'github-sync-daemon.js'); const daemon = spawn('node', [daemonPath], { stdio: 'inherit', env: process.env }); daemon.on('error', (err) => { console.error('❌ Failed to start sync daemon:', err.message); }); // Start the Next.js server const server = spawn('node', ['server.js'], { stdio: 'inherit', env: process.env, cwd: process.cwd() }); server.on('error', (err) => { console.error('❌ Failed to start Next.js server:', err.message); process.exit(1); }); server.on('exit', (code) => { console.log(`Next.js server exited with code ${code}`); daemon.kill(); process.exit(code); }); // Handle shutdown process.on('SIGTERM', () => { console.log('🛑 Received SIGTERM, shutting down...'); daemon.kill('SIGTERM'); server.kill('SIGTERM'); }); process.on('SIGINT', () => { console.log('🛑 Received SIGINT, shutting down...'); daemon.kill('SIGINT'); server.kill('SIGINT'); });