|
|
#!/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 startProcess(command, args, cwd, name, color) { |
|
|
const process = spawn(command, args, { |
|
|
cwd, |
|
|
stdio: 'pipe', |
|
|
shell: true |
|
|
}); |
|
|
|
|
|
|
|
|
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; |
|
|
} |
|
|
|
|
|
|
|
|
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'); |
|
|
|
|
|
|
|
|
const latexWatcher = startProcess( |
|
|
'npm', |
|
|
['run', 'latex:watch'], |
|
|
join(__dirname, '..'), |
|
|
'LaTeX', |
|
|
'blue' |
|
|
); |
|
|
|
|
|
|
|
|
const astroServer = startProcess( |
|
|
'npm', |
|
|
['run', 'dev'], |
|
|
join(__dirname, '..'), |
|
|
'Astro', |
|
|
'green' |
|
|
); |
|
|
|
|
|
|
|
|
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); |
|
|
} |
|
|
}); |
|
|
|