Skip to content

Commit

Permalink
fix: Categorization was broken with a single entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Dec 27, 2020
1 parent 23cb492 commit 7f6e924
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
5 changes: 5 additions & 0 deletions bin/typedoc
Expand Up @@ -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;
}
Expand Down
13 changes: 9 additions & 4 deletions src/lib/converter/plugins/CategoryPlugin.ts
Expand Up @@ -96,6 +96,8 @@ export class CategoryPlugin extends ConverterComponent {
return;
}
obj.groups.forEach((group) => {
if (group.categories) return;

group.categories = CategoryPlugin.getReflectionCategories(
group.children
);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
26 changes: 16 additions & 10 deletions src/lib/converter/plugins/GroupPlugin.ts
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -114,17 +110,27 @@ 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) => {
file.groups = GroupPlugin.getReflectionGroups(file.reflections);
});
}

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.
*
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Expand Up @@ -69,6 +69,7 @@ export interface TypeDocOptionMap {

help: boolean;
version: boolean;
showConfig: boolean;
plugin: string[];
logger: unknown; // string | Function
logLevel: typeof LogLevel;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -183,6 +183,11 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
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:
Expand Down

0 comments on commit 7f6e924

Please sign in to comment.