-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.ts
More file actions
25 lines (23 loc) · 1022 Bytes
/
clean.ts
File metadata and controls
25 lines (23 loc) · 1022 Bytes
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
import fs from 'fs/promises';
import path from 'path';
async function recursiveClean(dirPath: string): Promise<void> {
const directoryContent = await fs.readdir(dirPath);
const promises: Promise<unknown>[] = [];
for (let content of directoryContent) {
let localPath = path.join(dirPath, content);
const contentStats = await fs.lstat(localPath);
if (contentStats.isFile() &&
( localPath.endsWith('.command.js') ||
localPath.endsWith('.router.js') ||
localPath.endsWith('.class.js') ||
localPath.endsWith('.funct.js') )) {
promises.push(fs.rm(localPath).then(() => console.log(`Deleted : ${localPath}`)));
}
else if (contentStats.isDirectory() && content !== 'node_modules' && content !== '.git')
promises.push(recursiveClean(localPath));
}
await Promise.all(promises);
console.log(`Done with the ${dirPath} dirrectory`);
return;
}
recursiveClean(__dirname);