diff --git a/package.json b/package.json index e28aa2d..96a0955 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "verify": "bun run check && bun run build && bun run test:smoke", "test": "bun test", "test:smoke": "bun run scripts/smoke.ts", + "clean": "bun run scripts/clean.ts", "typecheck": "tsc --noEmit" }, "devDependencies": { diff --git a/scripts/clean.ts b/scripts/clean.ts new file mode 100644 index 0000000..87f493a --- /dev/null +++ b/scripts/clean.ts @@ -0,0 +1,19 @@ +import { readdir, rm } from "node:fs/promises"; +import { resolve } from "node:path"; + +const root = resolve(import.meta.dir, ".."); + +const patterns: Array<{ glob: string; desc: string }> = [ + { glob: ".build/", desc: "Bun 构建缓存" }, + { glob: ".*.bun-build", desc: "Bun 构建临时文件" }, +]; + +for (const { glob, desc } of patterns) { + const entries = await Array.fromAsync(new Bun.Glob(glob).scan({ root, dot: true })); + if (entries.length === 0) continue; + for (const entry of entries) { + const full = resolve(root, entry); + await rm(full, { recursive: true, force: true }); + console.log(`已清理 ${desc}: ${entry}`); + } +}