-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (27 loc) · 907 Bytes
/
script.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
import fs from 'fs';
import path from 'path';
// Specify the directory
const directoryPath = './lib';
// Function to delete files with specified extensions
const deleteFilesRecursively = (dir) => {
fs.readdir(dir, (err, files) => {
if (err) throw err;
files.forEach(file => {
const filePath = path.join(dir, file);
fs.stat(filePath, (err, stats) => {
if (err) throw err;
if (stats.isDirectory()) {
// Recurse into subdirectory
deleteFilesRecursively(filePath);
} else if (stats.isFile() && (file.endsWith('.d.ts') || file.endsWith('.js'))) {
fs.unlink(filePath, err => {
if (err) throw err;
console.log(`Deleted: ${filePath}`);
});
}
});
});
});
};
// Call the function
deleteFilesRecursively(directoryPath, ['.d.ts', '.js']);