mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Fix API generator
This commit is contained in:
@@ -785,47 +785,67 @@ const generateDocs = (entryFiles: string[], apiConfigFile: string) => {
|
|||||||
const constructorBlocks: string[] = [];
|
const constructorBlocks: string[] = [];
|
||||||
const allReferencedTypes: string[] = [];
|
const allReferencedTypes: string[] = [];
|
||||||
|
|
||||||
|
// First, process constructor parameters with visibility modifiers as properties from any constructor
|
||||||
|
// that has them (typically the implementation or the main signature)
|
||||||
|
let processedProperties = false;
|
||||||
constructorOverloads.forEach((ctor) => {
|
constructorOverloads.forEach((ctor) => {
|
||||||
// Skip the implementation (the one with a body) unless it's the only constructor
|
// Process constructor parameters with visibility modifiers as properties (only once)
|
||||||
if (ctor.body && constructorOverloads.length > 1) {
|
if (!processedProperties) {
|
||||||
// Process constructor parameters with visibility modifiers as properties (only from implementation)
|
const hasVisibilityParams = ctor.parameters.some(param =>
|
||||||
ctor.parameters.forEach((param) => {
|
param.modifiers?.some(mod =>
|
||||||
// Check if parameter has visibility modifier (public, private, protected, readonly)
|
|
||||||
const hasVisibilityModifier = param.modifiers?.some(mod =>
|
|
||||||
mod.kind === ts.SyntaxKind.PublicKeyword
|
mod.kind === ts.SyntaxKind.PublicKeyword
|
||||||
|| mod.kind === ts.SyntaxKind.PrivateKeyword
|
|| mod.kind === ts.SyntaxKind.PrivateKeyword
|
||||||
|| mod.kind === ts.SyntaxKind.ProtectedKeyword
|
|| mod.kind === ts.SyntaxKind.ProtectedKeyword
|
||||||
|| mod.kind === ts.SyntaxKind.ReadonlyKeyword,
|
|| mod.kind === ts.SyntaxKind.ReadonlyKeyword,
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (!hasVisibilityModifier) return;
|
if (hasVisibilityParams) {
|
||||||
|
ctor.parameters.forEach((param) => {
|
||||||
|
// Check if parameter has visibility modifier (public, private, protected, readonly)
|
||||||
|
const hasVisibilityModifier = param.modifiers?.some(mod =>
|
||||||
|
mod.kind === ts.SyntaxKind.PublicKeyword
|
||||||
|
|| mod.kind === ts.SyntaxKind.PrivateKeyword
|
||||||
|
|| mod.kind === ts.SyntaxKind.ProtectedKeyword
|
||||||
|
|| mod.kind === ts.SyntaxKind.ReadonlyKeyword,
|
||||||
|
);
|
||||||
|
|
||||||
// Skip private parameters
|
if (!hasVisibilityModifier) return;
|
||||||
const isPrivate = param.modifiers?.some(mod => mod.kind === ts.SyntaxKind.PrivateKeyword);
|
|
||||||
if (isPrivate) return;
|
|
||||||
|
|
||||||
const paramName = param.name.getText();
|
// Skip private parameters
|
||||||
const hasQuestionToken = param.questionToken !== undefined;
|
const isPrivate = param.modifiers?.some(mod => mod.kind === ts.SyntaxKind.PrivateKeyword);
|
||||||
const isReadonly = param.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ReadonlyKeyword);
|
if (isPrivate) return;
|
||||||
const rawParamType = param.type ? param.type.getText() : typeChecker.typeToString(typeChecker.getTypeAtLocation(param));
|
|
||||||
const paramType = cleanOptionalType(rawParamType, hasQuestionToken);
|
|
||||||
|
|
||||||
const propertyDef = `${isReadonly ? 'readonly ' : ''}${paramName}${hasQuestionToken ? '?' : ''}: ${paramType};`;
|
const paramName = param.name.getText();
|
||||||
|
const hasQuestionToken = param.questionToken !== undefined;
|
||||||
|
const isReadonly = param.modifiers?.some(mod => mod.kind === ts.SyntaxKind.ReadonlyKeyword);
|
||||||
|
const rawParamType = param.type ? param.type.getText() : typeChecker.typeToString(typeChecker.getTypeAtLocation(param));
|
||||||
|
const paramType = cleanOptionalType(rawParamType, hasQuestionToken);
|
||||||
|
|
||||||
// Get description from JSDoc comment on the parameter
|
const propertyDef = `${isReadonly ? 'readonly ' : ''}${paramName}${hasQuestionToken ? '?' : ''}: ${paramType};`;
|
||||||
const paramJsDoc = ts.getJSDocCommentsAndTags(param)[0];
|
|
||||||
let desc = '';
|
|
||||||
if (paramJsDoc && ts.isJSDoc(paramJsDoc) && typeof paramJsDoc.comment === 'string') {
|
|
||||||
desc = processLinkTags(paramJsDoc.comment.trim(), className);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find referenced types
|
// Get description from JSDoc comment on the parameter
|
||||||
const references = filterToExportedTypes(findAllTypeReferences(paramType), className);
|
const paramJsDoc = ts.getJSDocCommentsAndTags(param)[0];
|
||||||
const referencesText = formatReferences(references);
|
let desc = '';
|
||||||
|
if (paramJsDoc && ts.isJSDoc(paramJsDoc) && typeof paramJsDoc.comment === 'string') {
|
||||||
|
desc = processLinkTags(paramJsDoc.comment.trim(), className);
|
||||||
|
}
|
||||||
|
|
||||||
const propertyContent = `### \`${paramName}\`\n\n\`\`\`ts\n${propertyDef}\n\`\`\`${desc ? `\n\n${desc}` : ''}${referencesText}`;
|
// Find referenced types
|
||||||
properties.push(propertyContent);
|
const references = filterToExportedTypes(findAllTypeReferences(paramType), className);
|
||||||
});
|
const referencesText = formatReferences(references);
|
||||||
|
|
||||||
|
const propertyContent = `### \`${paramName}\`\n\n\`\`\`ts\n${propertyDef}\n\`\`\`${desc ? `\n\n${desc}` : ''}${referencesText}`;
|
||||||
|
properties.push(propertyContent);
|
||||||
|
});
|
||||||
|
processedProperties = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
constructorOverloads.forEach((ctor) => {
|
||||||
|
// Skip the implementation (the one with a body) unless it's the only constructor
|
||||||
|
if (ctor.body && constructorOverloads.length > 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user