// Скрипт для запуска Next.js dev с автоматическим поиском свободного порта const { spawn } = require('child_process'); const { findFreePort } = require('./findPort'); const DEFAULT_PORT = 3000; (async () => { try { const port = await findFreePort(DEFAULT_PORT); if (port !== DEFAULT_PORT) { console.log(`⚠️ Порт ${DEFAULT_PORT} занят, используем порт ${port}`); } else { console.log(`✅ Порт ${port} свободен`); } // Запускаем Next.js dev с найденным портом const nextDev = spawn('npx', ['next', 'dev', '--turbopack', '-p', String(port)], { stdio: 'inherit', shell: true, }); nextDev.on('error', (error) => { console.error('Ошибка запуска Next.js:', error); process.exit(1); }); nextDev.on('exit', (code) => { process.exit(code || 0); }); // Обработка Ctrl+C process.on('SIGINT', () => { nextDev.kill('SIGINT'); }); } catch (error) { console.error('Ошибка поиска порта:', error.message); process.exit(1); } })();