Skip to content

Commit 641c4e6

Browse files
committed
generate services as functions
1 parent cc4062b commit 641c4e6

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

packages/documentation/scripts/typedoc-generator.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,32 @@ async function generateDocsForEntrypoint(
8484
}
8585

8686
function getPropertyType(property: any): string {
87+
if (!property?.type) {
88+
console.log(`=== Type ${property?.name || 'unknown'} has no type property`);
89+
return 'unknown';
90+
}
91+
8792
if (property.type instanceof IntrinsicType) {
8893
return property.type.name;
8994
} else if (property.type instanceof ReferenceType) {
90-
return property.type.qualifiedName;
95+
// Handle generic types like Promise<ModalInstance<TReason>>
96+
if (property.type.typeArguments && property.type.typeArguments.length > 0) {
97+
const baseType = property.type.qualifiedName || property.type.name;
98+
const typeArgs = property.type.typeArguments
99+
.map((arg: any) => getPropertyType({ type: arg }))
100+
.join(', ');
101+
return `${baseType}<${typeArgs}>`;
102+
}
103+
return property.type.qualifiedName || property.type.name;
91104
} else if (property.type instanceof UnionType) {
92105
return property.type.types
93106
.filter((t: any) => 'name' in t)
94107
.map((t: any) => t.name)
95108
.join(' | ');
96109
} else {
97-
console.log(`=== Type ${property.name} is unknown`);
110+
console.log(`=== Type ${property?.name || 'unknown'} is unknown`);
111+
console.log('property.type:', property?.type);
112+
console.log('property.type constructor:', property?.type?.constructor?.name);
98113
return 'unknown';
99114
}
100115
}
@@ -170,7 +185,7 @@ function processFunctionSignature(child: any): FunctionDocProperty {
170185
type: getPropertyType(param),
171186
optional: param.flags?.isOptional,
172187
})) || [],
173-
returnType: getPropertyType(signature.type),
188+
returnType: getPropertyType({ type: signature.type }),
174189
comment: getCommentSummary(child),
175190
tags: extractCommentTags(child),
176191
};
@@ -194,8 +209,12 @@ function processProjectChildren(
194209
// Identifies simple functions (like closeModal) or complex functions (like showMessage/showModalLoading)
195210
const isFunction = child.signatures?.length > 0;
196211

212+
// Identifies classes/services (like ModalService)
213+
// TypeDoc kind 128 = Class
214+
const isClass = child.kind === 128;
215+
197216
// Identifies type/interface definitions (like ModalConfig)
198-
const isType = !child.signatures?.length;
217+
const isType = !child.signatures?.length && !isClass;
199218

200219
if (isFunction) {
201220
// 1. Process the main function signature (e.g., showModalLoading, showMessage)
@@ -215,6 +234,26 @@ function processProjectChildren(
215234
}
216235
}
217236
}
237+
} else if (isClass) {
238+
// Process class methods (like methods in ModalService)
239+
if (child.children) {
240+
const methods: any[] = [];
241+
for (const classChild of child.children) {
242+
// Process methods but skip constructors
243+
// TypeDoc kind 2048 = Method, kind 512 = Constructor
244+
if (classChild.signatures?.length > 0 && classChild.kind === 2048) {
245+
const methodDoc = processFunctionSignature(classChild);
246+
methods.push(methodDoc);
247+
}
248+
}
249+
250+
if (methods.length > 0) {
251+
if (!functionGroups.has(source)) {
252+
functionGroups.set(source, []);
253+
}
254+
functionGroups.get(source)!.push(...methods);
255+
}
256+
}
218257
} else if (isType) {
219258
// Process Types and Interfaces
220259
const properties = processProperties(child);

0 commit comments

Comments
 (0)