bolt.diy/scripts/clean.js
2025-01-30 23:28:21 +01:00

46 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { rm, existsSync } from 'fs';
import { join } from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const dirsToRemove = ['node_modules/.vite', 'node_modules/.cache', '.cache', 'dist'];
console.log('🧹 Cleaning project...');
// Remove directories
for (const dir of dirsToRemove) {
const fullPath = join(__dirname, '..', dir);
try {
if (existsSync(fullPath)) {
console.log(`Removing ${dir}...`);
rm(fullPath, { recursive: true, force: true }, (err) => {
if (err) {
console.error(`Error removing ${dir}:`, err.message);
}
});
}
} catch (err) {
console.error(`Error removing ${dir}:`, err.message);
}
}
// Run pnpm commands
console.log('\n📦 Reinstalling dependencies...');
try {
execSync('pnpm install', { stdio: 'inherit' });
console.log('\n🗑 Clearing pnpm cache...');
execSync('pnpm cache clean', { stdio: 'inherit' });
console.log('\n🏗 Rebuilding project...');
execSync('pnpm build', { stdio: 'inherit' });
console.log('\n✨ Clean completed! You can now run pnpm dev');
} catch (err) {
console.error('\n❌ Error during cleanup:', err.message);
process.exit(1);
}