From 2ab815450d7de12d7d63c46f6192aae2eb6e9b36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 12 Aug 2023 11:16:01 +0200 Subject: [PATCH] docs: make the typedoc generation portable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc.js | 1 + .gitignore | 1 + package.json | 2 +- typedoc.json | 2 +- typedoc.mjs | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 typedoc.mjs diff --git a/.eslintrc.js b/.eslintrc.js index 3a35e685..0188819b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -66,6 +66,7 @@ module.exports = defineConfig({ 'jsdoc', 'microjob', 'mjs', + 'npx', 'num', 'os', 'perf', diff --git a/.gitignore b/.gitignore index 2dea9b80..404473ff 100644 --- a/.gitignore +++ b/.gitignore @@ -77,5 +77,6 @@ package-lock.json *.bak lib dist +tmp reports/ benchmarks/internal/results/ diff --git a/package.json b/package.json index 4c07c976..d2f72a57 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:fix": "eslint . --cache --fix", "lint:report": "eslint . --cache --format json --output-file reports/eslint.json", "release": "release-it", - "typedoc": "mkdir ./tmp && cp ./docs/*.md ./tmp && typedoc && cp ./tmp/*.md ./docs && rm -rf ./tmp", + "typedoc": "node typedoc.mjs", "prepublishOnly": "pnpm build:prod" }, "ts-standard": { diff --git a/typedoc.json b/typedoc.json index 0512900b..d95b2637 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,6 +1,6 @@ { "$schema": "https://typedoc.org/schema.json", - "tsconfig": "./tsconfig.production.json", + "tsconfig": "tsconfig.production.json", "entryPoints": ["src"], "out": "docs", "readme": "none", diff --git a/typedoc.mjs b/typedoc.mjs new file mode 100644 index 00000000..b9f9cc99 --- /dev/null +++ b/typedoc.mjs @@ -0,0 +1,32 @@ +import { copyFileSync, mkdirSync, readdirSync, rmSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' +import { execSync } from 'node:child_process' + +try { + mkdirSync(join(dirname(fileURLToPath(import.meta.url)), 'tmp'), { + recursive: true + }) + const markdownFiles = readdirSync( + join(dirname(fileURLToPath(import.meta.url)), 'docs') + ).filter(file => file.endsWith('.md')) + for (const markdownFile of markdownFiles) { + copyFileSync( + join(dirname(fileURLToPath(import.meta.url)), 'docs', markdownFile), + join(dirname(fileURLToPath(import.meta.url)), 'tmp', markdownFile) + ) + } + execSync('npx typedoc', { stdio: 'inherit' }) + for (const markdownFile of markdownFiles) { + copyFileSync( + join(dirname(fileURLToPath(import.meta.url)), 'tmp', markdownFile), + join(dirname(fileURLToPath(import.meta.url)), 'docs', markdownFile) + ) + } + rmSync(join(dirname(fileURLToPath(import.meta.url)), 'tmp'), { + recursive: true, + force: true + }) +} catch (e) { + console.error(e) +} -- 2.34.1