forked from OnedocLabs/react-print-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprune.ts
29 lines (22 loc) · 871 Bytes
/
prune.ts
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
// List all the folder paths contained in the docs/images/previews directory
import { readdirSync, readFileSync, rmSync } from "fs";
import { glob } from "glob";
const dir = "docs/images/previews";
const folders = readdirSync(dir, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
// List all the mdx files contained in the docs directory
const mdxFiles = glob.sync("docs/**/*.mdx");
let unusedPreviews = folders;
// For each mdx file, check if it contains a preview image
mdxFiles.forEach((file) => {
const content = readFileSync(file, "utf-8");
unusedPreviews = unusedPreviews.filter(
(preview) => !content.includes(preview)
);
});
// Remove the previews that are still in the unusued
unusedPreviews.forEach((preview) => {
const path = `${dir}/${preview}`;
rmSync(path, { recursive: true });
});