-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcleanup.js
More file actions
44 lines (39 loc) · 1.55 KB
/
cleanup.js
File metadata and controls
44 lines (39 loc) · 1.55 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
const fs = require('fs');
const path = require('path');
const packagesDir = path.resolve(__dirname, 'packages');
console.log('Starting cleanup of node_modules folders inside packages...');
if (!fs.existsSync(packagesDir)) {
console.error(`Error: Packages directory not found at ${packagesDir}`);
process.exit(1);
}
// Read the packages directory
fs.readdir(packagesDir, (err, packages) => {
if (err) {
console.error('Error reading the packages directory:', err.message);
process.exit(1);
}
if (packages.length === 0) {
console.log('No packages found in the packages directory.');
process.exit(0);
}
packages.forEach((pkg) => {
const packagePath = path.join(packagesDir, pkg);
const nodeModulesPath = path.join(packagePath, 'node_modules','@flexilla');
if (fs.lstatSync(packagePath).isDirectory()) {
if (fs.existsSync(nodeModulesPath)) {
console.log(`Removing ${nodeModulesPath}...`);
try {
fs.rmSync(nodeModulesPath, { recursive: true, force: true });
console.log(`Successfully removed: ${nodeModulesPath}`);
} catch (err) {
console.error(`Failed to remove ${nodeModulesPath}:`, err.message);
}
} else {
console.log(`No node_modules found in ${packagePath}. Skipping.`);
}
} else {
console.log(`${packagePath} is not a directory. Skipping.`);
}
});
console.log('Cleanup complete!');
});