chore: reorganize docs apps (#7228)

* reorganize docs apps

* add README

* fix directory

* add condition for old docs
This commit is contained in:
Shahed Nasser
2024-05-03 17:36:38 +03:00
committed by GitHub
parent 224ebb2154
commit 4fe28f5a95
6187 changed files with 601447 additions and 598226 deletions
@@ -0,0 +1,70 @@
import { slugChanges } from "../generated/slug-changes.mjs"
import { readdirSync, statSync, writeFileSync } from "fs"
import path from "path"
const baseAppPath = path.resolve("app")
const baseReferencePath = path.resolve("references")
const monoRepoPath = path.resolve("..", "..", "..")
/**
*
* @param {string} options.dir - The directory to scan
* @param {string} options.basePath - The path to consider as base
* @returns {Promise<{ filePath: string; pathname: string; }[]>}
*/
async function scanFiles(options = {}) {
const { dir = "", basePath = baseAppPath, baseSlug = baseAppPath } = options
/**
* @type {{ filePath: string; pathname: string; }[]}
*/
const filesMap = []
const fullPath = path.resolve(basePath, dir.replace(/^\//, ""))
const files = readdirSync(fullPath)
for (const file of files) {
const filePath = path.join(fullPath, file)
const fileBasename = path.basename(file)
if (fileBasename !== "page.mdx" && statSync(filePath).isDirectory()) {
filesMap.push(
...(await scanFiles({
dir: filePath.replace(basePath, ""),
basePath,
baseSlug,
}))
)
continue
}
// check if it has a slug change and retrieve its new slug
const slugChange = slugChanges.find(
(item) => item.origSlug === filePath.replace(basePath, "")
)
const pathname =
slugChange?.newSlug ||
filePath.replace(baseSlug, "").replace(`/${fileBasename}`, "")
filesMap.push({
filePath: filePath.replace(monoRepoPath, ""),
pathname: pathname.length ? pathname : "/",
})
}
return filesMap
}
export async function main() {
const filesMap = await scanFiles()
filesMap.push(
...(await scanFiles({
basePath: baseReferencePath,
baseSlug: path.resolve(),
}))
)
// write files map
writeFileSync(
path.resolve("generated", "files-map.mjs"),
`export const filesMap = ${JSON.stringify(filesMap, null, 2)}`
)
}
@@ -0,0 +1,19 @@
import { writeFileSync } from "fs"
import getSlugs from "../utils/get-slugs.mjs"
import path from "path"
export async function main() {
const slugs = await getSlugs()
slugs.push(
...(await getSlugs({
basePath: path.resolve("references"),
baseSlug: path.resolve(),
}))
)
// write generated slugs
writeFileSync(
path.resolve("generated", "slug-changes.mjs"),
`export const slugChanges = ${JSON.stringify(slugs, null, 2)}`
)
}
+12
View File
@@ -0,0 +1,12 @@
import { generateSidebar } from "build-scripts"
import { main as generateSlugChanges } from "./generate-slug-changes.mjs"
import { main as generateFilesMap } from "./generate-files-map.mjs"
import { sidebar } from "../sidebar.mjs"
async function main() {
await generateSidebar(sidebar)
await generateSlugChanges()
await generateFilesMap()
}
void main()