Skip to content

Commit 72a22d4

Browse files
committed
refactor
1 parent 641c4e6 commit 72a22d4

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

packages/documentation/scripts/typedoc-generator.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import {
1919
} from 'typedoc';
2020
import { toKebabCase } from './utils/string-utils';
2121

22+
// TypeDoc ReflectionKind constants
23+
// See: https://typedoc.org/api/enums/Models.ReflectionKind.html
24+
const ReflectionKind = {
25+
Class: 128,
26+
Constructor: 512,
27+
Method: 2048,
28+
} as const;
29+
2230
export type TypeDocTarget = {
2331
name: string;
2432
properties?: TypeDocProperty[];
@@ -109,7 +117,10 @@ function getPropertyType(property: any): string {
109117
} else {
110118
console.log(`=== Type ${property?.name || 'unknown'} is unknown`);
111119
console.log('property.type:', property?.type);
112-
console.log('property.type constructor:', property?.type?.constructor?.name);
120+
console.log(
121+
'property.type constructor:',
122+
property?.type?.constructor?.name
123+
);
113124
return 'unknown';
114125
}
115126
}
@@ -206,26 +217,19 @@ function processProjectChildren(
206217
for (const child of project.children) {
207218
const source = path.relative(rootPath, child.sources![0].fullFileName);
208219

209-
// Identifies simple functions (like closeModal) or complex functions (like showMessage/showModalLoading)
210220
const isFunction = child.signatures?.length > 0;
211-
212-
// Identifies classes/services (like ModalService)
213-
// TypeDoc kind 128 = Class
214-
const isClass = child.kind === 128;
215-
216-
// Identifies type/interface definitions (like ModalConfig)
221+
const isClass = child.kind === ReflectionKind.Class;
217222
const isType = !child.signatures?.length && !isClass;
218223

219224
if (isFunction) {
220-
// 1. Process the main function signature (e.g., showModalLoading, showMessage)
221225
const functionDoc = processFunctionSignature(child);
222226

223227
if (!functionGroups.has(source)) {
224228
functionGroups.set(source, []);
225229
}
226230
functionGroups.get(source)!.push(functionDoc);
227231

228-
// 2. If the function has static properties (e.g., showMessage.info), process its children
232+
// If the function has static properties (e.g., showMessage.info), process its children
229233
if (child.children) {
230234
for (const staticProp of child.children) {
231235
if (staticProp.signatures?.length > 0) {
@@ -235,13 +239,14 @@ function processProjectChildren(
235239
}
236240
}
237241
} else if (isClass) {
238-
// Process class methods (like methods in ModalService)
239242
if (child.children) {
240243
const methods: any[] = [];
241244
for (const classChild of child.children) {
242245
// Process methods but skip constructors
243-
// TypeDoc kind 2048 = Method, kind 512 = Constructor
244-
if (classChild.signatures?.length > 0 && classChild.kind === 2048) {
246+
if (
247+
classChild.signatures?.length > 0 &&
248+
classChild.kind === ReflectionKind.Method
249+
) {
245250
const methodDoc = processFunctionSignature(classChild);
246251
methods.push(methodDoc);
247252
}
@@ -255,7 +260,6 @@ function processProjectChildren(
255260
}
256261
}
257262
} else if (isType) {
258-
// Process Types and Interfaces
259263
const properties = processProperties(child);
260264
types.push({
261265
name: child.name,

0 commit comments

Comments
 (0)