Skip to content

Commit

Permalink
docs(clients): remove excessive STS and SSO client from TOC (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Apr 15, 2021
1 parent 32b563b commit b7ff842
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { dirname } from "path";
import { ReferenceType } from "typedoc/dist/lib/models";
import { DeclarationReflection, Reflection, ReflectionKind } from "typedoc/dist/lib/models/reflections";
import {
DeclarationReflection,
ProjectReflection,
Reflection,
ReflectionKind,
} from "typedoc/dist/lib/models/reflections";
import { Component, RendererComponent } from "typedoc/dist/lib/output/components";
import { PageEvent } from "typedoc/dist/lib/output/events";
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem";
Expand All @@ -12,6 +18,7 @@ export class SdkClientTocPlugin extends RendererComponent {
private commandsNavigationItem?: NavigationItem;
private clientsNavigationItem?: NavigationItem;
private paginatorsNavigationItem?: NavigationItem;
private clientDir?: string;

initialize() {
// disable existing toc plugin
Expand Down Expand Up @@ -57,8 +64,10 @@ export class SdkClientTocPlugin extends RendererComponent {
model.kindOf(ReflectionKind.Class) &&
model.getFullName() !== "Client" && // Exclude the Smithy Client class.
(model.name.endsWith("Client") /* Modular client like S3Client */ ||
(extendedTypes.length === 1 &&
(extendedTypes[0] as ReferenceType).name.endsWith("Client"))) /* Legacy client like S3 */
extendedTypes.filter((reference) => (reference as ReferenceType).name === `${model.name}Client`).length > 0) &&
/* Filter out other client classes that not sourced from the same directory as current client. e.g. STS, SSO */
this.clientDir &&
dirname(model.sources[0]?.file.fullFileName) === this.clientDir
);
}

Expand Down Expand Up @@ -93,6 +102,7 @@ export class SdkClientTocPlugin extends RendererComponent {
buildToc(model: Reflection, trail: Reflection[], parent: NavigationItem, restriction?: string[]) {
const index = trail.indexOf(model);
const children = model["children"] || [];
if (!this.clientDir) this.clientDir = this.loadClientDir(model);

if (index < trail.length - 1 && children.length > 40) {
const child = trail[index + 1];
Expand Down Expand Up @@ -131,4 +141,16 @@ export class SdkClientTocPlugin extends RendererComponent {
this.commandsNavigationItem?.children.sort((childA, childB) => childA.title.localeCompare(childB.title));
}
}

private loadClientDir(model: Reflection) {
let projectModel = (model as any) as ProjectReflection;
while (projectModel.constructor.name !== "ProjectReflection" && !projectModel.kindOf(ReflectionKind.SomeModule)) {
projectModel = projectModel.parent as ProjectReflection;
}
const clientsDirectory = (projectModel as ProjectReflection).directory.directories["clients"].directories;
const dir = Object.values(clientsDirectory).filter((directory) =>
directory?.files.find((file) => file.name.endsWith("Client.ts"))
)[0];
return dirname(dir?.files.find((file) => file.name.endsWith("Client.ts")).fullFileName);
}
}

0 comments on commit b7ff842

Please sign in to comment.