-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclean-modules.mjs
More file actions
45 lines (39 loc) · 948 Bytes
/
clean-modules.mjs
File metadata and controls
45 lines (39 loc) · 948 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { join } from "path";
import { rm, readdir } from "fs/promises";
const targets = [
"pnpm-lock.yaml",
".turbo",
".next",
".content-collections",
"build",
"dist",
"node_modules",
];
const workspaceDirs = ["apps", "packages"];
const root = process.cwd();
async function clean(dir) {
for (const target of targets) {
const fullPath = join(dir, target);
try {
await rm(fullPath, { recursive: true, force: true });
console.log(`|- 🗑️ Deleted: ${fullPath.replace(root, ".")}`);
} catch {
console.error(`|- ❌ Failed: ${fullPath.replace(root, ".")}`);
}
}
}
await clean(root);
for (const wsDir of workspaceDirs) {
const wsPath = join(root, wsDir);
let entries;
try {
entries = await readdir(wsPath, { withFileTypes: true });
} catch {
continue;
}
for (const entry of entries) {
if (entry.isDirectory()) {
await clean(join(wsPath, entry.name));
}
}
}