forked from utelecon/utelecon.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanupIntegration.ts
More file actions
34 lines (32 loc) · 860 Bytes
/
CleanupIntegration.ts
File metadata and controls
34 lines (32 loc) · 860 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
import type { AstroIntegration } from "astro";
import fs from "fs/promises";
import { basename, extname } from "path";
import { fileURLToPath } from "url";
import { glob } from "glob";
const source = [".md", ".markdown", ".mdx", ".astro"];
export function cleanup(): AstroIntegration {
return {
name: "cleanup",
hooks: {
"astro:build:done": async ({ dir }) => {
const path = fileURLToPath(dir);
const files = await glob("**/*", {
cwd: path,
nodir: true,
absolute: true,
ignore: "_astro/**/*",
});
await Promise.all(
files.map((file) => {
if (
source.includes(extname(file)) ||
basename(file).startsWith("_")
) {
return fs.rm(file);
}
}),
);
},
},
};
}