CoolFace
Apppublic

Pq234/robot-learning-tutorial

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
dev-with-latex.mjs102 linesDownload Raw Back to scripts
1#!/usr/bin/env node2 3import { spawn } from 'child_process';4import { join, dirname } from 'path';5import { fileURLToPath } from 'url';6 7const __filename = fileURLToPath(import.meta.url);8const __dirname = dirname(__filename);9 10console.log('๐Ÿš€ Starting development server with LaTeX watching...\n');11 12// Function to start a process13function startProcess(command, args, cwd, name, color) {14    const process = spawn(command, args, {15        cwd,16        stdio: 'pipe',17        shell: true18    });19 20    // Color codes21    const colors = {22        reset: '\x1b[0m',23        bright: '\x1b[1m',24        red: '\x1b[31m',25        green: '\x1b[32m',26        yellow: '\x1b[33m',27        blue: '\x1b[34m',28        magenta: '\x1b[35m',29        cyan: '\x1b[36m'30    };31 32    const prefix = `${colors[color]}[${name}]${colors.reset}`;33 34    process.stdout.on('data', (data) => {35        const lines = data.toString().split('\n').filter(line => line.trim());36        lines.forEach(line => {37            console.log(`${prefix} ${line}`);38        });39    });40 41    process.stderr.on('data', (data) => {42        const lines = data.toString().split('\n').filter(line => line.trim());43        lines.forEach(line => {44            console.log(`${prefix} ${colors.red}${line}${colors.reset}`);45        });46    });47 48    process.on('close', (code) => {49        console.log(`${prefix} ${colors.red}Process exited with code ${code}${colors.reset}`);50    });51 52    return process;53}54 55// Initial LaTeX conversion56console.log('๐Ÿ“š Converting LaTeX to MDX initially...');57const initialConvert = spawn('npm', ['run', 'latex:convert'], {58    cwd: join(__dirname, '..'),59    stdio: 'inherit'60});61 62initialConvert.on('close', (code) => {63    if (code === 0) {64        console.log('โœ… Initial LaTeX conversion completed!\n');65 66        // Start LaTeX watcher67        const latexWatcher = startProcess(68            'npm',69            ['run', 'latex:watch'],70            join(__dirname, '..'),71            'LaTeX',72            'blue'73        );74 75        // Start Astro dev server76        const astroServer = startProcess(77            'npm',78            ['run', 'dev'],79            join(__dirname, '..'),80            'Astro',81            'green'82        );83 84        // Handle graceful shutdown85        process.on('SIGINT', () => {86            console.log('\n๐Ÿ›‘ Shutting down development servers...');87            latexWatcher.kill();88            astroServer.kill();89            process.exit(0);90        });91 92        console.log('๐ŸŽ‰ Development environment ready!');93        console.log('   ๐Ÿ“ LaTeX files: Watch mode active for scripts/latex-to-mdx/input/');94        console.log('   ๐ŸŒ Astro server: http://localhost:4321');95        console.log('   ๐Ÿ”„ Any change in LaTeX input/ will auto-regenerate MDX\n');96 97    } else {98        console.error('โŒ Initial LaTeX conversion failed!');99        process.exit(1);100    }101});102