Skip to content

Commit 5782e58

Browse files
authored
Merge branch 'main' into electron_newwindow
2 parents 6f0a264 + a5a90b5 commit 5782e58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1782
-640
lines changed

_regroup/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
"lorem-ipsum": "2.0.8",
4949
"rcedit": "4.0.1",
5050
"rimraf": "6.1.0",
51-
"tslib": "2.8.1",
52-
"typedoc": "0.28.14",
53-
"typedoc-plugin-missing-exports": "4.1.2"
51+
"tslib": "2.8.1"
5452
},
5553
"optionalDependencies": {
5654
"appdmg": "0.6.6"

_regroup/typedoc.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

apps/build-docs/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "build-docs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "src/main.ts",
6+
"scripts": {
7+
"start": "tsx ."
8+
},
9+
"keywords": [],
10+
"author": "Elian Doran <[email protected]>",
11+
"license": "AGPL-3.0-only",
12+
"packageManager": "[email protected]",
13+
"devDependencies": {
14+
"@redocly/cli": "2.10.0",
15+
"archiver": "7.0.1",
16+
"fs-extra": "11.3.2",
17+
"react": "19.2.0",
18+
"react-dom": "19.2.0",
19+
"typedoc": "0.28.14",
20+
"typedoc-plugin-missing-exports": "4.1.2"
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* The backend script API is accessible to code notes with the "JS (backend)" language.
3+
*
4+
* The entire API is exposed as a single global: {@link api}
5+
*
6+
* @module Backend Script API
7+
*/
8+
9+
/**
10+
* This file creates the entrypoint for TypeDoc that simulates the context from within a
11+
* script note on the server side.
12+
*
13+
* Make sure to keep in line with backend's `script_context.ts`.
14+
*/
15+
16+
export type { default as AbstractBeccaEntity } from "../../server/src/becca/entities/abstract_becca_entity.js";
17+
export type { default as BAttachment } from "../../server/src/becca/entities/battachment.js";
18+
export type { default as BAttribute } from "../../server/src/becca/entities/battribute.js";
19+
export type { default as BBranch } from "../../server/src/becca/entities/bbranch.js";
20+
export type { default as BEtapiToken } from "../../server/src/becca/entities/betapi_token.js";
21+
export type { BNote };
22+
export type { default as BOption } from "../../server/src/becca/entities/boption.js";
23+
export type { default as BRecentNote } from "../../server/src/becca/entities/brecent_note.js";
24+
export type { default as BRevision } from "../../server/src/becca/entities/brevision.js";
25+
26+
import BNote from "../../server/src/becca/entities/bnote.js";
27+
import BackendScriptApi, { type Api } from "../../server/src/services/backend_script_api.js";
28+
29+
export type { Api };
30+
31+
const fakeNote = new BNote();
32+
33+
/**
34+
* The `api` global variable allows access to the backend script API, which is documented in {@link Api}.
35+
*/
36+
export const api: Api = new BackendScriptApi(fakeNote, {});

apps/edit-docs/src/build-docs.ts renamed to apps/build-docs/src/build-docs.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ process.env.NODE_ENV = "development";
44

55
import cls from "@triliumnext/server/src/services/cls.js";
66
import { dirname, join, resolve } from "path";
7-
import fs, { copyFile } from "fs/promises";
8-
import fsExtra, { createWriteStream, type WriteStream } from "fs-extra";
7+
import * as fs from "fs/promises";
8+
import * as fsExtra from "fs-extra";
99
import archiver from "archiver";
10+
import { WriteStream } from "fs";
11+
import { execSync } from "child_process";
12+
import BuildContext from "./context.js";
1013

1114
const DOCS_ROOT = "../../../docs";
1215
const OUTPUT_DIR = "../../site";
1316

14-
async function main() {
17+
async function buildDocsInner() {
1518
const i18n = await import("@triliumnext/server/src/services/i18n.js");
1619
await i18n.initializeTranslations();
1720

@@ -30,7 +33,7 @@ async function main() {
3033
"export",
3134
null
3235
);
33-
const fileOutputStream = createWriteStream(zipFilePath);
36+
const fileOutputStream = fsExtra.createWriteStream(zipFilePath);
3437
await exportToZip(taskContext, branch, "share", fileOutputStream);
3538
await waitForStreamToFinish(fileOutputStream);
3639
await extractZip(zipFilePath, OUTPUT_DIR);
@@ -41,7 +44,7 @@ async function main() {
4144
}
4245

4346
// Copy favicon.
44-
await copyFile("../../apps/website/src/assets/favicon.ico", join(OUTPUT_DIR, "favicon.ico"));
47+
await fs.copyFile("../../apps/website/src/assets/favicon.ico", join(OUTPUT_DIR, "favicon.ico"));
4548

4649
console.log("Documentation built successfully!");
4750
}
@@ -106,4 +109,19 @@ export async function extractZip(zipFilePath: string, outputPath: string, ignore
106109
});
107110
}
108111

109-
cls.init(main);
112+
export default async function buildDocs({ gitRootDir }: BuildContext) {
113+
// Build the share theme.
114+
execSync(`pnpm run --filter share-theme build`, {
115+
stdio: "inherit",
116+
cwd: gitRootDir
117+
});
118+
119+
// Trigger the actual build.
120+
await new Promise((res, rej) => {
121+
cls.init(() => {
122+
buildDocsInner()
123+
.catch(rej)
124+
.then(res);
125+
});
126+
});
127+
}

apps/build-docs/src/context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default interface BuildContext {
2+
gitRootDir: string;
3+
baseDir: string;
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* The front script API is accessible to code notes with the "JS (frontend)" language.
3+
*
4+
* The entire API is exposed as a single global: {@link api}
5+
*
6+
* @module Frontend Script API
7+
*/
8+
9+
/**
10+
* This file creates the entrypoint for TypeDoc that simulates the context from within a
11+
* script note.
12+
*
13+
* Make sure to keep in line with frontend's `script_context.ts`.
14+
*/
15+
16+
export type { default as BasicWidget } from "../../client/src/widgets/basic_widget.js";
17+
export type { default as FAttachment } from "../../client/src/entities/fattachment.js";
18+
export type { default as FAttribute } from "../../client/src/entities/fattribute.js";
19+
export type { default as FBranch } from "../../client/src/entities/fbranch.js";
20+
export type { default as FNote } from "../../client/src/entities/fnote.js";
21+
export type { Api } from "../../client/src/services/frontend_script_api.js";
22+
export type { default as NoteContextAwareWidget } from "../../client/src/widgets/note_context_aware_widget.js";
23+
export type { default as RightPanelWidget } from "../../client/src/widgets/right_panel_widget.js";
24+
25+
import FrontendScriptApi, { type Api } from "../../client/src/services/frontend_script_api.js";
26+
27+
//@ts-expect-error
28+
export const api: Api = new FrontendScriptApi();

apps/build-docs/src/main.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { join } from "path";
2+
import BuildContext from "./context";
3+
import buildSwagger from "./swagger";
4+
import { existsSync, mkdirSync, rmSync } from "fs";
5+
import buildDocs from "./build-docs";
6+
import buildScriptApi from "./script-api";
7+
8+
const context: BuildContext = {
9+
gitRootDir: join(__dirname, "../../../"),
10+
baseDir: join(__dirname, "../../../site")
11+
};
12+
13+
async function main() {
14+
// Clean input dir.
15+
if (existsSync(context.baseDir)) {
16+
rmSync(context.baseDir, { recursive: true });
17+
}
18+
mkdirSync(context.baseDir);
19+
20+
// Start building.
21+
await buildDocs(context);
22+
buildSwagger(context);
23+
buildScriptApi(context);
24+
}
25+
26+
main();

apps/build-docs/src/script-api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { execSync } from "child_process";
2+
import BuildContext from "./context";
3+
import { join } from "path";
4+
5+
export default function buildScriptApi({ baseDir, gitRootDir }: BuildContext) {
6+
// Generate types
7+
execSync(`pnpm typecheck`, { stdio: "inherit", cwd: gitRootDir });
8+
9+
for (const config of [ "backend", "frontend" ]) {
10+
const outDir = join(baseDir, "script-api", config);
11+
execSync(`pnpm typedoc --options typedoc.${config}.json --html "${outDir}"`, {
12+
stdio: "inherit"
13+
});
14+
}
15+
}

apps/build-docs/src/swagger.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import BuildContext from "./context";
2+
import { join } from "path";
3+
import { execSync } from "child_process";
4+
import { mkdirSync } from "fs";
5+
6+
interface BuildInfo {
7+
specPath: string;
8+
outDir: string;
9+
}
10+
11+
const DIR_PREFIX = "rest-api";
12+
13+
const buildInfos: BuildInfo[] = [
14+
{
15+
// Paths are relative to Git root.
16+
specPath: "apps/server/internal.openapi.yaml",
17+
outDir: `${DIR_PREFIX}/internal`
18+
},
19+
{
20+
specPath: "apps/server/etapi.openapi.yaml",
21+
outDir: `${DIR_PREFIX}/etapi`
22+
}
23+
];
24+
25+
export default function buildSwagger({ baseDir, gitRootDir }: BuildContext) {
26+
for (const { specPath, outDir } of buildInfos) {
27+
const absSpecPath = join(gitRootDir, specPath);
28+
const targetDir = join(baseDir, outDir);
29+
mkdirSync(targetDir, { recursive: true });
30+
execSync(`pnpm redocly build-docs ${absSpecPath} -o ${targetDir}/index.html`, { stdio: "inherit" });
31+
}
32+
}

0 commit comments

Comments
 (0)