-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoptimize-build.mjs
More file actions
65 lines (53 loc) · 1.62 KB
/
optimize-build.mjs
File metadata and controls
65 lines (53 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs/promises';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function optimizeBuild() {
console.log('🚀 Starting build optimization...');
try {
// Clean up node_modules cache
const cacheDirectories = [
'node_modules/.cache',
'frontend/node_modules/.cache',
'.cache',
'frontend/.cache',
'backend/.cache'
];
for (const dir of cacheDirectories) {
try {
await fs.rm(join(__dirname, dir), { recursive: true, force: true });
console.log(`✅ Cleaned ${dir}`);
} catch (error) {
console.log(`⚠️ Cache directory ${dir} not found or already clean`);
}
}
// Check for common issues
console.log('🔍 Checking for common build issues...');
// Check if all required files exist
const requiredFiles = [
'frontend/package.json',
'backend/package.json',
'backend/functions/server.mjs',
'netlify.toml'
];
for (const file of requiredFiles) {
try {
await fs.access(join(__dirname, file));
console.log(`✅ ${file} exists`);
} catch (error) {
console.error(`❌ Missing required file: ${file}`);
process.exit(1);
}
}
console.log('✨ Build optimization complete!');
} catch (error) {
console.error('❌ Optimization failed:', error);
process.exit(1);
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
optimizeBuild();
}
export default optimizeBuild;