-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-sourcemaps.mjs
More file actions
36 lines (32 loc) · 844 Bytes
/
Copy pathclean-sourcemaps.mjs
File metadata and controls
36 lines (32 loc) · 844 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
import { rmSync } from "node:fs";
import { resolve } from "node:path";
const roots = [
resolve(import.meta.dirname, "..", "dist", "main"),
resolve(import.meta.dirname, "..", "dist", "renderer"),
];
async function* walk(dir) {
let entries;
try {
entries = await import("node:fs/promises").then(({ readdir }) =>
readdir(dir, { withFileTypes: true }),
);
} catch (error) {
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
return;
}
throw error;
}
for (const entry of entries) {
const path = resolve(dir, entry.name);
if (entry.isDirectory()) {
yield* walk(path);
} else if (entry.isFile() && path.endsWith(".map")) {
yield path;
}
}
}
for (const root of roots) {
for await (const file of walk(root)) {
rmSync(file);
}
}