generated from SachaWildCode/angular-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.js
44 lines (38 loc) · 957 Bytes
/
delete.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
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('fs');
const path = require('path');
function deleteSpecFiles(dir) {
fs.readdir(dir, (err, files) => {
if (err) {
console.error(`Error reading directory ${dir}:`, err);
return;
}
files.forEach(file => {
const filePath = path.join(dir, file);
handleFile(filePath, file);
});
});
}
function handleFile(filePath, file) {
fs.stat(filePath, (err, stat) => {
if (err) {
console.error(`Error stating file ${filePath}:`, err);
return;
}
if (stat.isDirectory()) {
deleteSpecFiles(filePath);
} else if (file.endsWith('.spec.ts')) {
deleteFile(filePath);
}
});
}
function deleteFile(filePath) {
fs.unlink(filePath, err => {
if (err) {
console.error(`Error deleting file ${filePath}:`, err);
} else {
console.log(`Deleted file: ${filePath}`);
}
});
}
// Start deleting from the current directory
deleteSpecFiles(__dirname);