#!/usr/bin/env node import { spawn } from 'child_process'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); console.log('šŸš€ Starting development server with LaTeX watching...\n'); // Function to start a process function startProcess(command, args, cwd, name, color) { const process = spawn(command, args, { cwd, stdio: 'pipe', shell: true }); // Color codes const colors = { reset: '\x1b[0m', bright: '\x1b[1m', red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', blue: '\x1b[34m', magenta: '\x1b[35m', cyan: '\x1b[36m' }; const prefix = `${colors[color]}[${name}]${colors.reset}`; process.stdout.on('data', (data) => { const lines = data.toString().split('\n').filter(line => line.trim()); lines.forEach(line => { console.log(`${prefix} ${line}`); }); }); process.stderr.on('data', (data) => { const lines = data.toString().split('\n').filter(line => line.trim()); lines.forEach(line => { console.log(`${prefix} ${colors.red}${line}${colors.reset}`); }); }); process.on('close', (code) => { console.log(`${prefix} ${colors.red}Process exited with code ${code}${colors.reset}`); }); return process; } // Initial LaTeX conversion console.log('šŸ“š Converting LaTeX to MDX initially...'); const initialConvert = spawn('npm', ['run', 'latex:convert'], { cwd: join(__dirname, '..'), stdio: 'inherit' }); initialConvert.on('close', (code) => { if (code === 0) { console.log('āœ… Initial LaTeX conversion completed!\n'); // Start LaTeX watcher const latexWatcher = startProcess( 'npm', ['run', 'latex:watch'], join(__dirname, '..'), 'LaTeX', 'blue' ); // Start Astro dev server const astroServer = startProcess( 'npm', ['run', 'dev'], join(__dirname, '..'), 'Astro', 'green' ); // Handle graceful shutdown process.on('SIGINT', () => { console.log('\nšŸ›‘ Shutting down development servers...'); latexWatcher.kill(); astroServer.kill(); process.exit(0); }); console.log('šŸŽ‰ Development environment ready!'); console.log(' šŸ“ LaTeX files: Watch mode active for scripts/latex-to-mdx/input/'); console.log(' 🌐 Astro server: http://localhost:4321'); console.log(' šŸ”„ Any change in LaTeX input/ will auto-regenerate MDX\n'); } else { console.error('āŒ Initial LaTeX conversion failed!'); process.exit(1); } });