MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / clean

Function clean

scripts/clean.ts:26–56  ·  view source on GitHub ↗
(dir: string, depth: number)

Source from the content-addressed store, hash-verified

24const maxDepth = 5;
25
26function clean(dir: string, depth: number) {
27 if (depth > maxDepth) return;
28 let entries: fs.Dirent[];
29 try {
30 entries = fs.readdirSync(dir, { withFileTypes: true });
31 } catch {
32 return;
33 }
34 for (const entry of entries) {
35 const full = path.join(dir, entry.name);
36 if (entry.isDirectory()) {
37 if (nestedTargets.has(entry.name)) {
38 try {
39 fs.rmSync(full, { recursive: true, force: true });
40 console.log("removed", full);
41 } catch (e: any) {
42 console.warn("skipped (in use?):", full, "-", e.message);
43 }
44 } else {
45 clean(full, depth + 1);
46 }
47 } else if (entry.isFile() && nestedGlobs.test(entry.name)) {
48 try {
49 fs.rmSync(full, { force: true });
50 console.log("removed", full);
51 } catch (e: any) {
52 console.warn("skipped (in use?):", full, "-", e.message);
53 }
54 }
55 }
56}
57
58for (const dir of searchRoots) {
59 clean(path.join(root, dir), 1);

Callers 1

clean.tsFile · 0.85

Calls 2

logMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected