@ts-for-gir/generator-json 4.0.0-beta.39 → 4.0.0-beta.41
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/README.md +72 -50
- package/package.json +10 -6
- package/src/gir-metadata-deserializer.ts +34 -0
- package/src/gir-metadata-index.ts +66 -0
- package/src/gir-metadata-serializer.ts +237 -0
- package/src/gir-metadata-types.ts +132 -0
- package/src/index.ts +3 -1
- package/src/json-definition-generator.ts +77 -28
- package/src/typedoc-pipeline.ts +581 -0
- package/src/json-generator.ts +0 -425
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { GirModule, NSRegistry, OptionsGeneration } from "@ts-for-gir/lib";
|
|
5
|
+
import { Reporter, ReporterService } from "@ts-for-gir/lib";
|
|
6
|
+
|
|
7
|
+
import { TypeDocPipeline } from "./typedoc-pipeline.ts";
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
|
-
* Generator
|
|
6
|
-
*
|
|
10
|
+
* Generator that produces TypeDoc JSON output from GIR modules.
|
|
11
|
+
*
|
|
12
|
+
* Uses {@link TypeDocPipeline} for the shared .d.ts → TypeDoc conversion,
|
|
13
|
+
* then serializes each ProjectReflection to JSON.
|
|
7
14
|
*/
|
|
8
15
|
export class JsonDefinitionGenerator {
|
|
9
16
|
readonly log: Reporter;
|
|
10
17
|
readonly config: OptionsGeneration;
|
|
11
18
|
readonly registry: NSRegistry;
|
|
12
19
|
|
|
20
|
+
private readonly pipeline: TypeDocPipeline;
|
|
21
|
+
|
|
13
22
|
constructor(config: OptionsGeneration, registry: NSRegistry) {
|
|
14
23
|
this.config = config;
|
|
15
24
|
this.registry = registry;
|
|
25
|
+
this.pipeline = new TypeDocPipeline(config, registry);
|
|
16
26
|
this.log = new Reporter(
|
|
17
27
|
this.config.verbose,
|
|
18
28
|
JsonDefinitionGenerator.name,
|
|
@@ -20,42 +30,81 @@ export class JsonDefinitionGenerator {
|
|
|
20
30
|
this.config.reporterOutput,
|
|
21
31
|
);
|
|
22
32
|
|
|
23
|
-
// Register with reporter service if reporting is enabled
|
|
24
33
|
if (this.config.reporter) {
|
|
25
|
-
|
|
26
|
-
reporterService.registerReporter(JsonDefinitionGenerator.name, this.log);
|
|
34
|
+
ReporterService.getInstance().registerReporter(JsonDefinitionGenerator.name, this.log);
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
|
|
38
|
+
public async start(): Promise<void> {
|
|
39
|
+
this.log.info("Starting JSON generation via TypeDoc...");
|
|
40
|
+
await this.pipeline.start();
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
public async generate(module: GirModule): Promise<void> {
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
await this.pipeline.generate(module);
|
|
45
|
+
}
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
public async finish(girModules: GirModule[]): Promise<void> {
|
|
48
|
+
await this.pipeline.finishTypescriptGeneration(girModules);
|
|
49
|
+
|
|
50
|
+
try {
|
|
35
51
|
if (this.config.outdir) {
|
|
36
|
-
|
|
37
|
-
const fs = await import("node:fs/promises");
|
|
38
|
-
const path = await import("node:path");
|
|
39
|
-
|
|
40
|
-
const filename = `${module.packageName}.json`;
|
|
41
|
-
const filepath = path.join(this.config.outdir, filename);
|
|
42
|
-
|
|
43
|
-
await fs.writeFile(filepath, output, "utf8");
|
|
44
|
-
this.log.info(`Generated ${filename}`);
|
|
45
|
-
} else {
|
|
46
|
-
// Output to console
|
|
47
|
-
this.log.log(output);
|
|
52
|
+
await mkdir(this.config.outdir, { recursive: true });
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
|
|
55
|
+
for (const module of this.pipeline.modules) {
|
|
56
|
+
await this.generateTypeDocJson(module);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Always generate JSON for the GJS core types package
|
|
60
|
+
await this.generateGjsJson();
|
|
61
|
+
|
|
62
|
+
if (this.config.outdir) {
|
|
63
|
+
this.log.success(
|
|
64
|
+
`JSON generation completed for ${this.pipeline.modules.length} modules in ${this.config.outdir}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
} finally {
|
|
68
|
+
await this.pipeline.cleanup();
|
|
51
69
|
}
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
|
|
55
|
-
this.
|
|
72
|
+
private async generateGjsJson(): Promise<void> {
|
|
73
|
+
const result = await this.pipeline.createGjsTypeDocApp();
|
|
74
|
+
if (!result) {
|
|
75
|
+
this.log.info("GJS package not available, skipping JSON generation for GJS");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { app, project } = result;
|
|
80
|
+
const gjsDir = this.pipeline.getGjsDir();
|
|
81
|
+
const jsonOutput = app.serializer.projectToObject(project, gjsDir);
|
|
82
|
+
const pretty = this.config.verbose;
|
|
83
|
+
const jsonStr = `${JSON.stringify(jsonOutput, null, pretty ? "\t" : "")}\n`;
|
|
84
|
+
|
|
85
|
+
if (this.config.outdir) {
|
|
86
|
+
const filepath = join(this.config.outdir, "Gjs.json");
|
|
87
|
+
await writeFile(filepath, jsonStr, "utf8");
|
|
88
|
+
this.log.info(`Generated ${filepath}`);
|
|
89
|
+
} else {
|
|
90
|
+
this.log.log(jsonStr);
|
|
91
|
+
}
|
|
56
92
|
}
|
|
57
93
|
|
|
58
|
-
|
|
59
|
-
|
|
94
|
+
private async generateTypeDocJson(module: GirModule): Promise<void> {
|
|
95
|
+
const { app, project } = await this.pipeline.createTypeDocApp(module);
|
|
96
|
+
const moduleDir = this.pipeline.getModuleDir(module);
|
|
97
|
+
|
|
98
|
+
const jsonOutput = app.serializer.projectToObject(project, moduleDir);
|
|
99
|
+
const pretty = this.config.verbose;
|
|
100
|
+
const jsonStr = `${JSON.stringify(jsonOutput, null, pretty ? "\t" : "")}\n`;
|
|
101
|
+
|
|
102
|
+
if (this.config.outdir) {
|
|
103
|
+
const filepath = join(this.config.outdir, `${module.packageName}.json`);
|
|
104
|
+
await writeFile(filepath, jsonStr, "utf8");
|
|
105
|
+
this.log.info(`Generated ${filepath}`);
|
|
106
|
+
} else {
|
|
107
|
+
this.log.log(jsonStr);
|
|
108
|
+
}
|
|
60
109
|
}
|
|
61
110
|
}
|