|
| 1 | +/* eslint-disable no-console */ |
| 2 | +import { join } from "node:path"; |
| 3 | +import type { Application } from "../application.js"; |
| 4 | +import { Reflection, type SomeReflection } from "../models/index.js"; |
| 5 | +import type { SerializerComponent } from "../serialization/components.js"; |
| 6 | +import type { JSONOutput } from "../serialization/index.js"; |
| 7 | + |
| 8 | +const serializer: SerializerComponent<SomeReflection> = { |
| 9 | + priority: 0, |
| 10 | + supports(x) { |
| 11 | + return x instanceof Reflection; |
| 12 | + }, |
| 13 | + toObject(item, obj: any) { |
| 14 | + obj.url = item.url; |
| 15 | + obj.hasOwnDocument = item.hasOwnDocument; |
| 16 | + // obj.anchor = item.anchor; |
| 17 | + delete obj.sources; |
| 18 | + delete obj.groups; |
| 19 | + delete obj.categories; |
| 20 | + delete obj.readme; |
| 21 | + delete obj.content; |
| 22 | + delete obj.kind; |
| 23 | + delete obj.flags; |
| 24 | + delete obj.defaultValue; |
| 25 | + delete obj.symbolIdMap; |
| 26 | + delete obj.files; |
| 27 | + delete obj.packageName; |
| 28 | + delete obj.variant; |
| 29 | + delete obj.extendedTypes; |
| 30 | + delete obj.inheritedFrom; |
| 31 | + if (!["reflection", "reference"].includes(obj.type?.type)) { |
| 32 | + delete obj.type; |
| 33 | + } |
| 34 | + |
| 35 | + if (obj.comment) { |
| 36 | + obj.comment.summary = obj.comment.summary.filter( |
| 37 | + (part: JSONOutput.CommentDisplayPart) => |
| 38 | + part.kind === "inline-tag", |
| 39 | + ); |
| 40 | + obj.comment.blockTags = obj.comment.blockTags?.filter( |
| 41 | + (tag: JSONOutput.CommentTag) => { |
| 42 | + tag.content = tag.content.filter( |
| 43 | + (part) => part.kind === "inline-tag", |
| 44 | + ); |
| 45 | + return tag.content.length; |
| 46 | + }, |
| 47 | + ); |
| 48 | + |
| 49 | + if ( |
| 50 | + !obj.comment.summary.length && |
| 51 | + !obj.comment.blockTags?.length && |
| 52 | + !obj.comment.modifierTags |
| 53 | + ) { |
| 54 | + delete obj.comment; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return obj; |
| 59 | + }, |
| 60 | +}; |
| 61 | + |
| 62 | +export function debugRendererUrls( |
| 63 | + app: Application, |
| 64 | + { json = false, logs = false } = { logs: true }, |
| 65 | +) { |
| 66 | + app.renderer.postRenderAsyncJobs.push(async (evt) => { |
| 67 | + if (json) { |
| 68 | + app.serializer.addSerializer(serializer); |
| 69 | + await app.generateJson( |
| 70 | + evt.project, |
| 71 | + join(evt.outputDirectory, "url_debug.json"), |
| 72 | + ); |
| 73 | + app.serializer.removeSerializer(serializer); |
| 74 | + } |
| 75 | + |
| 76 | + if (logs) { |
| 77 | + for (const id in evt.project.reflections) { |
| 78 | + const refl = evt.project.reflections[id]; |
| 79 | + console.log( |
| 80 | + refl.id, |
| 81 | + refl.getFullName(), |
| 82 | + refl.url, |
| 83 | + refl.hasOwnDocument, |
| 84 | + ); |
| 85 | + } |
| 86 | + } |
| 87 | + }); |
| 88 | +} |
0 commit comments