refactor(build-docs): integrate with original build-docs script

This commit is contained in:
Elian Doran
2025-11-01 20:37:03 +02:00
parent ecf12a4063
commit 6e06d7169f
6 changed files with 40 additions and 32 deletions

View File

@@ -12,6 +12,8 @@
"packageManager": "pnpm@10.19.0",
"devDependencies": {
"@redocly/cli": "2.10.0",
"archiver": "7.0.1",
"fs-extra": "11.3.2",
"react": "19.2.0",
"react-dom": "19.2.0"
}

View File

@@ -4,14 +4,15 @@ process.env.NODE_ENV = "development";
import cls from "@triliumnext/server/src/services/cls.js";
import { dirname, join, resolve } from "path";
import fs, { copyFile } from "fs/promises";
import fsExtra, { createWriteStream, type WriteStream } from "fs-extra";
import * as fs from "fs/promises";
import * as fsExtra from "fs-extra";
import archiver from "archiver";
import { WriteStream } from "fs";
const DOCS_ROOT = "../../../docs";
const OUTPUT_DIR = "../../site";
async function main() {
async function buildDocsInner() {
const i18n = await import("@triliumnext/server/src/services/i18n.js");
await i18n.initializeTranslations();
@@ -30,7 +31,7 @@ async function main() {
"export",
null
);
const fileOutputStream = createWriteStream(zipFilePath);
const fileOutputStream = fsExtra.createWriteStream(zipFilePath);
await exportToZip(taskContext, branch, "share", fileOutputStream);
await waitForStreamToFinish(fileOutputStream);
await extractZip(zipFilePath, OUTPUT_DIR);
@@ -41,7 +42,7 @@ async function main() {
}
// Copy favicon.
await copyFile("../../apps/website/src/assets/favicon.ico", join(OUTPUT_DIR, "favicon.ico"));
await fs.copyFile("../../apps/website/src/assets/favicon.ico", join(OUTPUT_DIR, "favicon.ico"));
console.log("Documentation built successfully!");
}
@@ -106,4 +107,12 @@ export async function extractZip(zipFilePath: string, outputPath: string, ignore
});
}
cls.init(main);
export default async function buildDocs() {
return new Promise((res, rej) => {
cls.init(() => {
buildDocsInner()
.catch(rej)
.then(res);
});
});
}

View File

@@ -1,3 +1,4 @@
export default interface BuildContext {
gitRootDir: string;
baseDir: string;
}

View File

@@ -2,17 +2,20 @@ import { join } from "path";
import BuildContext from "./context";
import buildSwagger from "./swagger";
import { mkdirSync, rmSync } from "fs";
import buildDocs from "./build-docs";
const context: BuildContext = {
gitRootDir: join(__dirname, "../../../"),
baseDir: join(__dirname, "../../../site")
};
function main() {
async function main() {
// Clean input dir.
rmSync(context.baseDir, { recursive: true });
mkdirSync(context.baseDir);
// Start building.
await buildDocs();
buildSwagger(context);
}

View File

@@ -10,19 +10,21 @@ interface BuildInfo {
const buildInfos: BuildInfo[] = [
{
specPath: join(__dirname, "../../server/src/assets/api-openapi.yaml"),
// Paths are relative to Git root.
specPath: "apps/server/src/assets/api-openapi.yaml",
outDir: "api/internal"
},
{
specPath: join(__dirname, "../../server/src/assets/etapi.openapi.yaml"),
specPath: "apps/server/src/assets/etapi.openapi.yaml",
outDir: "api/etapi"
}
];
export default function buildSwagger({ baseDir }: BuildContext) {
export default function buildSwagger({ baseDir, gitRootDir }: BuildContext) {
for (const { specPath, outDir } of buildInfos) {
const absSpecPath = join(gitRootDir, specPath);
const targetDir = join(baseDir, outDir);
mkdirSync(outDir, { recursive: true });
execSync(`pnpm redocly build-docs ${specPath} -o ${targetDir}/index.html`, { stdio: "inherit" });
execSync(`pnpm redocly build-docs ${absSpecPath} -o ${targetDir}/index.html`, { stdio: "inherit" });
}
}

33
pnpm-lock.yaml generated
View File

@@ -130,6 +130,12 @@ importers:
'@redocly/cli':
specifier: 2.10.0
version: 2.10.0(@opentelemetry/api@1.9.0)(ajv@8.17.1)(bufferutil@4.0.9)(core-js@3.46.0)(encoding@0.1.13)(utf-8-validate@6.0.5)
archiver:
specifier: 7.0.1
version: 7.0.1
fs-extra:
specifier: 11.3.2
version: 11.3.2
react:
specifier: 19.2.0
version: 19.2.0
@@ -6014,9 +6020,6 @@ packages:
balanced-match@2.0.0:
resolution: {integrity: sha512-1ugUSr8BHXRnK23KfuYS+gVMC3LB8QGH9W1iGtDPsNWoQbgtXSExkBu2aDR4epiGWZOjZsj6lDl/N/AqqTC3UA==}
bare-events@2.5.4:
resolution: {integrity: sha512-+gFfDkR8pj4/TrWCGUGWmJIkBwuxPS5F+a5yWjOHQt2hHvNZd5YLzadjmDUtFmMM4y429bnKLa8bYBMHcYdnQA==}
bare-events@2.7.0:
resolution: {integrity: sha512-b3N5eTW1g7vXkw+0CXh/HazGTcO5KYuu/RCNaJbDMPI6LHDi+7qe8EmxKUVe1sUbY2KZOVZFyj62x0OEz9qyAA==}
@@ -13091,9 +13094,6 @@ packages:
resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==}
engines: {node: '>=10.0.0'}
streamx@2.22.0:
resolution: {integrity: sha512-sLh1evHOzBy/iWRiR6d1zRcLao4gGZr3C1kzNz4fopCOKJb6xD9ub8Mpi9Mr1R6id5o43S+d93fI48UC5uM9aw==}
streamx@2.23.0:
resolution: {integrity: sha512-kn+e44esVfn2Fa/O0CPFcex27fjIL6MkVae0Mm6q+E6f0hWv578YCERbv+4m02cjxvDsPKLnmxral/rR6lBMAg==}
@@ -15438,6 +15438,8 @@ snapshots:
'@ckeditor/ckeditor5-core': 47.1.0
'@ckeditor/ckeditor5-utils': 47.1.0
ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-code-block@47.1.0(patch_hash=2361d8caad7d6b5bddacc3a3b4aa37dbfba260b1c1b22a450413a79c1bb1ce95)':
dependencies:
@@ -16188,6 +16190,8 @@ snapshots:
'@ckeditor/ckeditor5-ui': 47.1.0
'@ckeditor/ckeditor5-utils': 47.1.0
ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41)
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-restricted-editing@47.1.0':
dependencies:
@@ -21231,11 +21235,7 @@ snapshots:
balanced-match@2.0.0: {}
bare-events@2.5.4:
optional: true
bare-events@2.7.0:
optional: true
bare-events@2.7.0: {}
bare-fs@4.4.5:
dependencies:
@@ -23775,7 +23775,6 @@ snapshots:
events-universal@1.0.1:
dependencies:
bare-events: 2.7.0
optional: true
events@3.3.0: {}
@@ -29917,19 +29916,11 @@ snapshots:
streamsearch@1.1.0: {}
streamx@2.22.0:
dependencies:
fast-fifo: 1.3.2
text-decoder: 1.2.3
optionalDependencies:
bare-events: 2.5.4
streamx@2.23.0:
dependencies:
events-universal: 1.0.1
fast-fifo: 1.3.2
text-decoder: 1.2.3
optional: true
strict-event-emitter@0.5.1:
optional: true
@@ -30442,7 +30433,7 @@ snapshots:
dependencies:
b4a: 1.6.7
fast-fifo: 1.3.2
streamx: 2.22.0
streamx: 2.23.0
tar@6.2.1:
dependencies: