@ts-for-gir/generator-html-doc 4.0.0-beta.40 → 4.0.0-beta.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/generator-html-doc",
3
- "version": "4.0.0-beta.40",
3
+ "version": "4.0.0-beta.42",
4
4
  "description": "HTML Documentation generator for ts-for-gir",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -34,12 +34,16 @@
34
34
  ".": "./src/index.ts"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/node": "^24.11.0",
37
+ "@ts-for-gir/tsconfig": "^4.0.0-beta.42",
38
+ "@types/node": "^24.12.0",
38
39
  "rimraf": "^6.1.3",
39
40
  "typescript": "^5.9.3"
40
41
  },
41
42
  "dependencies": {
42
- "@ts-for-gir/generator-base": "^4.0.0-beta.40",
43
- "@ts-for-gir/lib": "^4.0.0-beta.40"
43
+ "@ts-for-gir/generator-base": "^4.0.0-beta.42",
44
+ "@ts-for-gir/generator-json": "^4.0.0-beta.42",
45
+ "@ts-for-gir/lib": "^4.0.0-beta.42",
46
+ "@ts-for-gir/typedoc-theme": "^4.0.0-beta.42",
47
+ "typedoc": "^0.28.17"
44
48
  }
45
49
  }
@@ -1,29 +1,105 @@
1
- import type { Generator } from "@ts-for-gir/generator-base";
2
- import type { GirModule, NSRegistry, OptionsGeneration } from "@ts-for-gir/lib";
3
- import { DANGER_HTML_DOC_GENERATOR_NOT_IMPLEMENTED, Logger } from "@ts-for-gir/lib";
1
+ import { mkdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+
4
+ import { type TypeDocAppResult, TypeDocPipeline } from "@ts-for-gir/generator-json";
5
+ import { type GirModule, type NSRegistry, type OptionsGeneration, Reporter, ReporterService } from "@ts-for-gir/lib";
6
+ import { load as loadGiDocgenTheme } from "@ts-for-gir/typedoc-theme";
7
+ import type { Application } from "typedoc";
4
8
 
5
9
  /**
6
- * A template that can be used to implement an HTML Documentation Generator
10
+ * Generator that produces HTML documentation from GIR modules using TypeDoc.
11
+ *
12
+ * Uses {@link TypeDocPipeline} for the shared .d.ts → TypeDoc conversion,
13
+ * then generates HTML documentation via TypeDoc's built-in renderer.
7
14
  */
8
- export class HtmlDocGenerator implements Generator {
9
- protected log: Logger;
10
- protected readonly config: OptionsGeneration;
11
- protected readonly registry: NSRegistry;
15
+ export class HtmlDocGenerator {
16
+ readonly log: Reporter;
17
+ readonly config: OptionsGeneration;
18
+ readonly registry: NSRegistry;
19
+
20
+ private readonly pipeline: TypeDocPipeline;
21
+
12
22
  constructor(config: OptionsGeneration, registry: NSRegistry) {
13
23
  this.config = config;
14
24
  this.registry = registry;
15
- this.log = new Logger(config.verbose, HtmlDocGenerator.name);
25
+ this.pipeline = new TypeDocPipeline(config, registry);
26
+ this.log = new Reporter(
27
+ this.config.verbose,
28
+ HtmlDocGenerator.name,
29
+ this.config.reporter,
30
+ this.config.reporterOutput,
31
+ );
32
+
33
+ if (this.config.reporter) {
34
+ ReporterService.getInstance().registerReporter(HtmlDocGenerator.name, this.log);
35
+ }
36
+ }
37
+
38
+ public async start(): Promise<void> {
39
+ this.log.info("Starting HTML documentation generation via TypeDoc...");
40
+ await this.pipeline.start();
41
+ }
42
+
43
+ public async generate(module: GirModule): Promise<void> {
44
+ await this.pipeline.generate(module);
45
+ }
46
+
47
+ public async finish(girModules: GirModule[]): Promise<void> {
48
+ await this.pipeline.finishTypescriptGeneration(girModules);
49
+
50
+ try {
51
+ const outdir = this.requireOutdir();
52
+ await mkdir(outdir, { recursive: true });
53
+
54
+ if (this.config.combined) {
55
+ const result = await this.pipeline.createCombinedTypeDocApp();
56
+ await this.generateDocsWithTheme(result, outdir);
57
+ } else {
58
+ for (const module of this.pipeline.modules) {
59
+ const result = await this.pipeline.createTypeDocApp(module);
60
+ await this.generateDocsWithTheme(result, join(outdir, module.packageName));
61
+ }
62
+ }
63
+
64
+ this.log.success(`HTML documentation generated for ${this.pipeline.modules.length} modules in ${outdir}`);
65
+ } finally {
66
+ await this.pipeline.cleanup();
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Generate combined HTML documentation from pre-generated TypeDoc JSON files.
72
+ * This bypasses the normal .d.ts generation pipeline entirely, using TypeDoc's merge mode.
73
+ */
74
+ public async generateFromJson(jsonDir: string): Promise<void> {
75
+ const outdir = this.requireOutdir();
76
+ await mkdir(outdir, { recursive: true });
77
+
78
+ this.log.info(`Generating HTML documentation from JSON files in ${jsonDir}...`);
79
+ const result = await this.pipeline.createMergedTypeDocApp(jsonDir);
80
+ await this.generateDocsWithTheme(result, outdir);
81
+ this.log.success(`Generated merged HTML docs from JSON in ${outdir}`);
16
82
  }
17
83
 
18
- async start(): Promise<void> {
19
- return Promise.resolve(this.log.danger(DANGER_HTML_DOC_GENERATOR_NOT_IMPLEMENTED));
84
+ /** Apply the configured theme and generate HTML docs into the given directory. */
85
+ private async generateDocsWithTheme({ app, project }: TypeDocAppResult, outdir: string): Promise<void> {
86
+ this.applyTheme(app);
87
+ await app.generateDocs(project, outdir);
20
88
  }
21
89
 
22
- generate(_module: GirModule): Promise<void> {
23
- throw new Error("Method not implemented.");
90
+ private applyTheme(app: Application): void {
91
+ const themeName = this.config.theme || "gi-docgen";
92
+ if (themeName === "gi-docgen") {
93
+ loadGiDocgenTheme(app);
94
+ }
95
+ app.options.setValue("theme", themeName);
24
96
  }
25
97
 
26
- finish(_girModules: GirModule[]): Promise<void> {
27
- throw new Error("Method not implemented.");
98
+ /** Returns outdir or throws if not configured. */
99
+ private requireOutdir(): string {
100
+ if (!this.config.outdir) {
101
+ throw new Error("HTML documentation requires --outdir to be specified");
102
+ }
103
+ return this.config.outdir;
28
104
  }
29
105
  }