@ts-for-gir/generator-json 4.0.0-beta.44 → 4.0.0-rc.2

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-json",
3
- "version": "4.0.0-beta.44",
3
+ "version": "4.0.0-rc.2",
4
4
  "description": "JSON generator for ts-for-gir",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -36,17 +36,17 @@
36
36
  "json"
37
37
  ],
38
38
  "devDependencies": {
39
- "@ts-for-gir/tsconfig": "^4.0.0-beta.44",
40
- "@types/node": "^24.12.0",
39
+ "@ts-for-gir/tsconfig": "^4.0.0-rc.2",
40
+ "@types/node": "^24.12.2",
41
41
  "typescript": "^6.0.2"
42
42
  },
43
43
  "dependencies": {
44
- "@gi.ts/parser": "^4.0.0-beta.44",
45
- "@ts-for-gir/generator-base": "^4.0.0-beta.44",
46
- "@ts-for-gir/generator-typescript": "^4.0.0-beta.44",
47
- "@ts-for-gir/gir-module-metadata": "^4.0.0-beta.44",
48
- "@ts-for-gir/lib": "^4.0.0-beta.44",
49
- "@ts-for-gir/reporter": "^4.0.0-beta.44",
44
+ "@gi.ts/parser": "^4.0.0-rc.2",
45
+ "@ts-for-gir/generator-base": "^4.0.0-rc.2",
46
+ "@ts-for-gir/generator-typescript": "^4.0.0-rc.2",
47
+ "@ts-for-gir/gir-module-metadata": "^4.0.0-rc.2",
48
+ "@ts-for-gir/lib": "^4.0.0-rc.2",
49
+ "@ts-for-gir/reporter": "^4.0.0-rc.2",
50
50
  "typedoc": "^0.28.18"
51
51
  }
52
52
  }
@@ -115,6 +115,8 @@ export interface GirNamespaceMetadata {
115
115
  description?: string;
116
116
  /** Logo/icon URL */
117
117
  logoUrl?: string;
118
+ /** Icon filename from refs/library-icons (e.g. "librsvg-r.svg") */
119
+ iconFile?: string;
118
120
  /** Project website URL */
119
121
  websiteUrl?: string;
120
122
  /** URL to upstream C API documentation */
@@ -128,6 +128,15 @@ export class TypeDocPipeline {
128
128
  result.project.packageVersion = module.libraryVersion.toString();
129
129
 
130
130
  this.registerGirMetadata(result.app, module);
131
+
132
+ // Attach metadata directly to module reflections for HTML rendering.
133
+ // registerGirMetadata only hooks into the serializer (for JSON export);
134
+ // the theme needs metadata on the reflections themselves.
135
+ const nsMeta = this.buildNamespaceMetadata(module);
136
+ for (const child of result.project.children ?? []) {
137
+ (child as unknown as { girNamespaceMetadata?: GirNamespaceMetadata }).girNamespaceMetadata ??= nsMeta;
138
+ }
139
+
131
140
  return result;
132
141
  }
133
142
 
@@ -215,6 +224,7 @@ export class TypeDocPipeline {
215
224
  [new TSConfigReader()],
216
225
  );
217
226
  this.fixExportImportReferences(result.project);
227
+ this.enrichModuleReflections(result.project);
218
228
  return result;
219
229
  }
220
230
 
@@ -240,9 +250,75 @@ export class TypeDocPipeline {
240
250
 
241
251
  const result = await this.convertApp(app, "merged documentation");
242
252
  this.fixExportImportReferences(result.project);
253
+ this.enrichMergedModuleMetadata(result.project);
243
254
  return result;
244
255
  }
245
256
 
257
+ /**
258
+ * Enrich module reflections with curated metadata after merge.
259
+ *
260
+ * In merge mode, girNamespaceMetadata lives at the project-root level of
261
+ * each individual JSON file. When TypeDoc merges these files, the metadata
262
+ * may not be transferred to the resulting module reflections. This method
263
+ * fills in missing metadata from the curated registry so that the theme
264
+ * can always categorise and describe every module.
265
+ */
266
+ private enrichMergedModuleMetadata(project: ProjectReflection): void {
267
+ if (!project.children) return;
268
+ for (const child of project.children) {
269
+ const enriched = child as DeclarationReflection & { girNamespaceMetadata?: GirNamespaceMetadata };
270
+ // Skip modules that already have a category from the JSON deserializer
271
+ if (enriched.girNamespaceMetadata?.category) continue;
272
+
273
+ // Try to find curated metadata by matching the module name to a GIR ID.
274
+ // Module names in the merged project follow the pattern "Namespace-Version"
275
+ // (e.g. "Gtk-4.0") which matches the girId used in the metadata registry.
276
+ const meta = getModuleMetadata(child.name);
277
+ if (!meta) continue;
278
+
279
+ const existing = enriched.girNamespaceMetadata ?? ({} as GirNamespaceMetadata);
280
+ enriched.girNamespaceMetadata = {
281
+ ...existing,
282
+ displayName: existing.displayName ?? meta.displayName,
283
+ description: existing.description ?? meta.description,
284
+ logoUrl:
285
+ existing.logoUrl ?? meta.logoUrl ?? (meta.iconFile ? `assets/library-icons/${meta.iconFile}` : undefined),
286
+ iconFile: existing.iconFile ?? meta.iconFile,
287
+ websiteUrl: existing.websiteUrl ?? meta.websiteUrl,
288
+ cDocsUrl: existing.cDocsUrl ?? meta.cDocsUrl,
289
+ license: existing.license ?? meta.license,
290
+ category: existing.category ?? meta.category,
291
+ };
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Attach metadata to module reflections by matching against known GIR modules.
297
+ * Used in combined mode where modules are discovered via "packages" entry point strategy.
298
+ */
299
+ private enrichModuleReflections(project: ProjectReflection): void {
300
+ if (!project.children) return;
301
+
302
+ // Build lookup maps: by importName (e.g. "rsvg-2.0") and by packageName (e.g. "Rsvg-2.0")
303
+ const metaByImportName = new Map<string, GirNamespaceMetadata>();
304
+ for (const module of this.modules) {
305
+ metaByImportName.set(module.importName, this.buildNamespaceMetadata(module));
306
+ }
307
+
308
+ for (const child of project.children) {
309
+ const enriched = child as DeclarationReflection & { girNamespaceMetadata?: GirNamespaceMetadata };
310
+ if (enriched.girNamespaceMetadata?.category) continue;
311
+
312
+ // Module name may be scoped (e.g. "@girs/rsvg-2.0") — extract the importName part
313
+ const scopeMatch = child.name.match(/^@[^/]+\/(.+)$/);
314
+ const importName = scopeMatch ? scopeMatch[1] : child.name.toLowerCase();
315
+ const nsMeta = metaByImportName.get(importName);
316
+ if (nsMeta) {
317
+ enriched.girNamespaceMetadata ??= nsMeta;
318
+ }
319
+ }
320
+ }
321
+
246
322
  async cleanup(): Promise<void> {
247
323
  if (this.tempDir) {
248
324
  await rm(this.tempDir, { recursive: true, force: true });
@@ -635,7 +711,8 @@ export class TypeDocPipeline {
635
711
  packageVersion: pkgJson?.version,
636
712
  displayName: meta?.displayName,
637
713
  description: meta?.description ?? pkgJson?.description,
638
- logoUrl: meta?.logoUrl,
714
+ logoUrl: meta?.logoUrl ?? (meta?.iconFile ? `assets/library-icons/${meta.iconFile}` : undefined),
715
+ iconFile: meta?.iconFile,
639
716
  websiteUrl: meta?.websiteUrl ?? pkgJson?.homepage,
640
717
  cDocsUrl: meta?.cDocsUrl,
641
718
  license: meta?.license ?? pkgJson?.license,