Skip to content

Commit

Permalink
Adds prune script to remove unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
Titou325 committed Feb 19, 2024
1 parent a68fb80 commit 4108333
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
29 changes: 29 additions & 0 deletions docgen/prune.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 });
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
"build": "tsup --external @onedoc/react-print",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "(cd ./docs && mintlify dev --watch)",
"build-components": "npm run build && tsx ./docgen/index.ts"
"build-components": "npm run build && tsx ./docgen/index.ts",
"prune-docs": "tsx ./docgen/prune.ts",
"build-component-commit": "npm run build-components && npm run prune-docs"
},
"pre-commit": [
"build-components"
"build-components-commit"
],
"author": "",
"license": "ISC",
Expand Down

0 comments on commit 4108333

Please sign in to comment.