From 7f6e924035adce5b8a5520a4d9c3940dd1f54702 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 26 Dec 2020 21:51:49 -0700 Subject: [PATCH] fix: Categorization was broken with a single entry point --- bin/typedoc | 5 ++++ src/lib/converter/plugins/CategoryPlugin.ts | 13 +++++++---- src/lib/converter/plugins/GroupPlugin.ts | 26 +++++++++++++-------- src/lib/utils/options/declaration.ts | 1 + src/lib/utils/options/sources/typedoc.ts | 5 ++++ 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/bin/typedoc b/bin/typedoc index 5ba85a00f..7c64abeec 100755 --- a/bin/typedoc +++ b/bin/typedoc @@ -42,6 +42,11 @@ async function run(app) { return ExitCodes.Ok; } + if (app.options.getValue("showConfig")) { + console.log(app.options.getRawValues()); + return ExitCodes.Ok; + } + if (app.logger.hasErrors()) { return ExitCodes.OptionError; } diff --git a/src/lib/converter/plugins/CategoryPlugin.ts b/src/lib/converter/plugins/CategoryPlugin.ts index 409475d40..152ba5606 100644 --- a/src/lib/converter/plugins/CategoryPlugin.ts +++ b/src/lib/converter/plugins/CategoryPlugin.ts @@ -96,6 +96,8 @@ export class CategoryPlugin extends ConverterComponent { return; } obj.groups.forEach((group) => { + if (group.categories) return; + group.categories = CategoryPlugin.getReflectionCategories( group.children ); @@ -112,7 +114,7 @@ export class CategoryPlugin extends ConverterComponent { } private lumpCategorize(obj: ContainerReflection) { - if (!obj.children || obj.children.length === 0) { + if (!obj.children || obj.children.length === 0 || obj.categories) { return; } obj.categories = CategoryPlugin.getReflectionCategories(obj.children); @@ -196,11 +198,14 @@ export class CategoryPlugin extends ConverterComponent { reflection.signatures ) { // If a reflection has signatures, use the first category tag amongst them - reflection.signatures.forEach((sig) => { - if (sig.comment && category === "") { + for (const sig of reflection.signatures) { + if (sig.comment) { category = extractCategoryTag(sig.comment); } - }); + if (category != "") { + break; + } + } } return category; } diff --git a/src/lib/converter/plugins/GroupPlugin.ts b/src/lib/converter/plugins/GroupPlugin.ts index f89a28cc6..5dc42fc60 100644 --- a/src/lib/converter/plugins/GroupPlugin.ts +++ b/src/lib/converter/plugins/GroupPlugin.ts @@ -9,6 +9,7 @@ import { SourceDirectory } from "../../models/sources/directory"; import { Component, ConverterComponent } from "../components"; import { Converter } from "../converter"; import { Context } from "../context"; +import { ReflectionCategory } from "../../models"; /** * A handler that sorts and groups the found reflections in the resolving phase. @@ -88,12 +89,7 @@ export class GroupPlugin extends ConverterComponent { reflection.kindString = GroupPlugin.getKindSingular(reflection.kind); if (reflection instanceof ContainerReflection) { - if (reflection.children && reflection.children.length > 0) { - reflection.children.sort(GroupPlugin.sortCallback); - reflection.groups = GroupPlugin.getReflectionGroups( - reflection.children - ); - } + this.group(reflection); } } @@ -114,10 +110,7 @@ export class GroupPlugin extends ConverterComponent { } const project = context.project; - if (project.children && project.children.length > 0) { - project.children.sort(GroupPlugin.sortCallback); - project.groups = GroupPlugin.getReflectionGroups(project.children); - } + this.group(project); walkDirectory(project.directory); project.files.forEach((file) => { @@ -125,6 +118,19 @@ export class GroupPlugin extends ConverterComponent { }); } + private group(reflection: ContainerReflection) { + if ( + reflection.children && + reflection.children.length > 0 && + !reflection.groups + ) { + reflection.children.sort(GroupPlugin.sortCallback); + reflection.groups = GroupPlugin.getReflectionGroups( + reflection.children + ); + } + } + /** * Create a grouped representation of the given list of reflections. * diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 9496d8609..56af568c0 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -69,6 +69,7 @@ export interface TypeDocOptionMap { help: boolean; version: boolean; + showConfig: boolean; plugin: string[]; logger: unknown; // string | Function logLevel: typeof LogLevel; diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index 645bc6059..722bd3ac8 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -183,6 +183,11 @@ export function addTypeDocOptions(options: Pick) { help: "Print TypeDoc's version.", type: ParameterType.Boolean, }); + options.addDeclaration({ + name: "showConfig", + help: "Print the resolved configuration and exit", + type: ParameterType.Boolean, + }); options.addDeclaration({ name: "plugin", help: