import fs from 'fs'; import { exec, execSync } from 'child_process'; import { promisify } from 'util'; const execPromise = promisify(exec); export function installDeps() { // check if node_modules exists if (fs.existsSync('./node_modules')) { return; } // install dependencies console.log('Installing mandatory dependencies...'); execSync('npm install --omit=dev', { stdio: 'inherit' }); console.log('Mandatory dependencies installed'); // install dev dependencies (in the background) console.log(); console.log(); console.log(); console.log('Installing dev dependencies...'); installDevDeps(); } async function installDevDeps(attempt = 1) { try { await execPromise('npm install', { stdio: 'inherit' }); console.log('Dev dependencies installed'); } catch (error) { console.error('Error installing dev dependencies:', error.message); if (attempt < 3) { const retryDelay = 5000 * attempt; console.log(`Retrying in ${Math.round(retryDelay / 1000)} seconds...`); setTimeout(() => installDevDeps(attempt + 1), retryDelay); } else { console.error('Failed to install dev dependencies.'); console.error('Please try again manually, by running "npm install" in the project directory.'); } } }