53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { execSync } from 'child_process';
|
|
|
|
const nodeModulesPath = './node_modules';
|
|
const packageJsonPath = './package.json';
|
|
|
|
try {
|
|
if (!fs.existsSync(packageJsonPath)) {
|
|
console.error('package.json not found. Please make sure you are in a valid Node.js project.');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!fs.existsSync(nodeModulesPath)) {
|
|
console.log('node_modules not found. Please run "npm install" to install dependencies.');
|
|
|
|
execSync('npm install', { stdio: 'inherit' });
|
|
|
|
console.log('Dependencies installed successfully. You can now run "npm run dev".');
|
|
process.exit(0);
|
|
} else {
|
|
console.log('node_modules found. Checking if dependencies are installed...');
|
|
|
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
|
|
const missingDependencies = [];
|
|
|
|
for (const depName of Object.keys(dependencies)) {
|
|
const depPath = path.join(nodeModulesPath, depName);
|
|
|
|
if (!fs.existsSync(depPath)) {
|
|
missingDependencies.push(depName);
|
|
}
|
|
}
|
|
|
|
if (missingDependencies.length === 0) {
|
|
console.log('All dependencies are installed.');
|
|
} else {
|
|
console.log('Missing one or more dependencies:');
|
|
missingDependencies.forEach((dep) => {
|
|
console.log(` - ${dep}`);
|
|
});
|
|
console.log('Manually run "npm install" to install the missing dependencies.');
|
|
process.exit(1);
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('Error checking dependencies:', error.message || error);
|
|
process.exit(1);
|
|
}
|
|
|