diff --git a/packages/client-documentation-generator/src/sdk-client-rename-project.ts b/packages/client-documentation-generator/src/sdk-client-rename-project.ts index 3f92f79d4a29..d366de605e0a 100644 --- a/packages/client-documentation-generator/src/sdk-client-rename-project.ts +++ b/packages/client-documentation-generator/src/sdk-client-rename-project.ts @@ -2,11 +2,14 @@ import { readFileSync } from "fs"; import { Component, RendererComponent } from "typedoc/dist/lib/output/components"; import { RendererEvent } from "typedoc/dist/lib/output/events"; +import { getCurrentClientDirectory } from "./utils"; + /** * Correct the package name in the navigator. */ @Component({ name: "SdkClientRenameProject" }) export class SdkClientRenameProjectPlugin extends RendererComponent { + private projectName: string | undefined = undefined; initialize() { this.listenTo(this.owner, { [RendererEvent.BEGIN]: this.onRenderedBegin, @@ -14,10 +17,19 @@ export class SdkClientRenameProjectPlugin extends RendererComponent { } onRenderedBegin(event: RendererEvent) { - const { fullFileName } = event.project.files.filter((sourceFile) => - sourceFile.fileName.endsWith("/package.json") - )[0]; - const { name } = JSON.parse(readFileSync(fullFileName).toString()); - event.project.name = name; + if (!this.projectName) { + const clientDirectory = getCurrentClientDirectory(event); + const metadataDir = clientDirectory.files.filter((sourceFile) => + sourceFile.fileName.endsWith("/package.json") + )?.[0]?.fullFileName; + const { name } = metadataDir || JSON.parse(readFileSync(metadataDir).toString()); + const serviceIdReflection = clientDirectory.files + ?.filter((sourceFile) => sourceFile.fileName.endsWith("/runtimeConfig.shared.ts"))?.[0] + .reflections.filter((reflection) => reflection.name === "serviceId")?.[0]; + this.projectName = serviceIdReflection /* serviceIdReflection.defaultValue looks like '"S3"' */ + ? `${(serviceIdReflection as any).defaultValue.match(/"(.*)"/)[1]} Client - AWS SDK for JavaScript v3` + : name; + } + event.project.name = this.projectName; } } diff --git a/packages/client-documentation-generator/src/sdk-client-toc-plugin.ts b/packages/client-documentation-generator/src/sdk-client-toc-plugin.ts index 7456d419068b..12dded6c7877 100644 --- a/packages/client-documentation-generator/src/sdk-client-toc-plugin.ts +++ b/packages/client-documentation-generator/src/sdk-client-toc-plugin.ts @@ -10,6 +10,8 @@ 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"; +import { getCurrentClientDirectory } from "./utils"; + /** * Group the ToC for easier observability. */ @@ -164,10 +166,7 @@ export class SdkClientTocPlugin extends RendererComponent { 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); + const clientsDirectory = getCurrentClientDirectory({ project: projectModel as ProjectReflection }); + return dirname(clientsDirectory?.files.find((file) => file.name.endsWith("Client.ts")).fullFileName); } } diff --git a/packages/client-documentation-generator/src/utils.ts b/packages/client-documentation-generator/src/utils.ts new file mode 100644 index 000000000000..0556a07a7aab --- /dev/null +++ b/packages/client-documentation-generator/src/utils.ts @@ -0,0 +1,8 @@ +import { ProjectReflection, SourceDirectory } from "typedoc/dist/lib/models"; + +export const getCurrentClientDirectory = (event: { project: ProjectReflection }): SourceDirectory => { + const clientsDirectory = event.project.directory.directories["clients"].directories; + return Object.values(clientsDirectory).filter((directory) => + directory?.files.find((file) => file.name.endsWith("Client.ts")) + )[0]; +};