From bf572506997253b70ec30451c842c3c686c976cd Mon Sep 17 00:00:00 2001 From: MaXFeeD <46795182+MaXFeeD@users.noreply.github.com> Date: Thu, 21 Mar 2024 04:50:54 +0300 Subject: [PATCH] Reference API --- api/.gitignore | 3 +++ api/package.json | 17 ++++++++++++--- api/tools/link_references.ts | 42 ++++++++++++++++++++++++++++++++++++ docusaurus.config.js | 2 +- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 api/tools/link_references.ts diff --git a/api/.gitignore b/api/.gitignore index f1e54cf7c..e2c1c97cb 100644 --- a/api/.gitignore +++ b/api/.gitignore @@ -1,6 +1,9 @@ # Dependencies node_modules/ +# Production +docs/ + # Generated files /media/codicons /.wireit diff --git a/api/package.json b/api/package.json index eaf83c045..ed3f58faa 100644 --- a/api/package.json +++ b/api/package.json @@ -17,7 +17,9 @@ ], "private": true, "scripts": { + "prebuild-theme": "wireit", "prebuild-declarations": "wireit", + "typedoc": "wireit", "build": "wireit" }, "wireit": { @@ -41,8 +43,8 @@ "declarations/core-engine.d.ts" ] }, - "build": { - "command": "typedoc --out ../src/pages/api declarations/core-engine.d.ts", + "typedoc": { + "command": "typedoc declarations/core-engine.d.ts", "files": [ "typedoc.json", "tsconfig-typedoc.json", @@ -54,7 +56,16 @@ "prebuild-declarations" ], "output": [ - "../src/pages/api" + "docs" + ] + }, + "build": { + "command": "tsx tools/link_references.ts", + "files": [ + "docs/**/*" + ], + "dependencies": [ + "typedoc" ] } }, diff --git a/api/tools/link_references.ts b/api/tools/link_references.ts new file mode 100644 index 000000000..cbffe521d --- /dev/null +++ b/api/tools/link_references.ts @@ -0,0 +1,42 @@ +/* + + Inner Core API: Core Engine API Reference + Copyright (C) 2023 Nernar (https://github.com/nernar) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Maintained and distributed by MaXFeeD (maxfeed.nernar@outlook.com) + +*/ + +import { join } from 'path'; +import { existsSync } from 'fs'; +import { symlink, mkdir } from 'fs/promises'; + +(async () => { + const website = join(__dirname, '..', '..', 'static'); + const api = join(website, 'api'); + if (!existsSync(api)) + { + const target = join(__dirname, '..', 'docs'); + if (!existsSync(target)) + { + console.error("Run `npm run typedoc` before running symlinking!"); + return; + } + await mkdir(website, { recursive: true }); + await symlink(target, api, 'dir'); + console.info("Successfully symlinked 'api'!"); + } +})(); diff --git a/docusaurus.config.js b/docusaurus.config.js index c9e5a7610..08d5cc6b0 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -205,7 +205,7 @@ const config = /** @type {import('@docusaurus/types').Config} */ ({ }) }); -const api = path.resolve('src/pages/api'); +const api = path.resolve('static/api'); if (fs.existsSync(api) && fs.readdirSync(api).length) { const themeConfig =