-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathclean.js
31 lines (27 loc) · 845 Bytes
/
clean.js
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
/*eslint no-undef: "off"*/
const fs = require('fs');
const path = require('path');
const foldersToDelete = ['/tsc', '/build', '/dist'];
function deleteFolderRecursive(folderPath) {
if (fs.existsSync(folderPath)) {
fs.readdirSync(folderPath).forEach((file) => {
const curPath = path.join(folderPath, file);
if (fs.lstatSync(curPath).isDirectory()) {
// Recursive call for directories
deleteFolderRecursive(curPath);
} else {
// Delete files
fs.unlinkSync(curPath);
}
});
// Delete the folder itself
fs.rmdirSync(folderPath);
}
}
// Delete specified folders
foldersToDelete.forEach((folder) => {
const folderPath = path.join(__dirname, folder);
deleteFolderRecursive(folderPath);
console.log(`Deleted ${folder}`);
});
console.log('Deletion process complete.');