From 1b49f8ce3864658b5b64e54a816b422e9c7b1ec5 Mon Sep 17 00:00:00 2001 From: dzek Date: Thu, 9 Jan 2025 19:00:58 +0100 Subject: [PATCH] ~ added missing build file --- typedoc.mjs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 typedoc.mjs diff --git a/typedoc.mjs b/typedoc.mjs new file mode 100644 index 0000000..d1f5de5 --- /dev/null +++ b/typedoc.mjs @@ -0,0 +1,49 @@ +import { readFile, writeFile, mkdtemp, copyFile } from "fs/promises"; +import { join } from "path"; +import { tmpdir } from "os"; +import * as pagesConfig from "./pagesconfig.json" with { type: "json" }; +const config = pagesConfig.default; +const tutorials = []; +const tempDir = await mkdtemp(join(tmpdir(), "ts-library-template-")); +const shouldPathUseRoot = (path) => !path.startsWith("./") && !path.startsWith("../") && !path.startsWith("/"); +const generateTitle = (title, group) => { + const tit = title.replace(/"/gu, `\\"`); + const sub = (group ?? "").replace(/"/gu, `\\"`); + const finalTitle = [sub, tit].filter(Boolean).join("/"); + return `--- +title: ${finalTitle} +--- +`; // leave the ending new line +}; +let i = 0; +// eslint-disable-next-line @typescript-eslint/no-shadow +const convertPages = async ({ pages, parent, root }) => { + for (const page of pages) { + if (page.source) { + const fullPath = shouldPathUseRoot(page.source) ? join(root ?? "", page.source) : page.source; + const tempPath = join(tempDir, `${i++}.md`); + tutorials.push(tempPath); + await copyFile(fullPath, tempPath); + await writeFile(tempPath, generateTitle(page.title, parent) + await readFile(fullPath, "utf-8")); + } + if (page.children) { + await convertPages({ + pages: page.children, + parent: parent ? parent + "/" + page.title : page.title, + root: page.moduleRoot ? join(root ?? "", page.childrenSourceDir ?? "") : root, + }); + } + } +}; +if (config.pages?.length) { + const root = config.source; + await convertPages({ pages: config.pages, parent: "", root: root }); +} +console.info({ + tutorials, + tempDir, +}); +export default { + projectDocuments: tutorials, + sortEntryPoints: false, +};