1
+ import { dirname } from "path" ;
1
2
import { ReferenceType } from "typedoc/dist/lib/models" ;
2
- import { DeclarationReflection , Reflection , ReflectionKind } from "typedoc/dist/lib/models/reflections" ;
3
+ import {
4
+ DeclarationReflection ,
5
+ ProjectReflection ,
6
+ Reflection ,
7
+ ReflectionKind ,
8
+ } from "typedoc/dist/lib/models/reflections" ;
3
9
import { Component , RendererComponent } from "typedoc/dist/lib/output/components" ;
4
10
import { PageEvent } from "typedoc/dist/lib/output/events" ;
5
11
import { NavigationItem } from "typedoc/dist/lib/output/models/NavigationItem" ;
@@ -12,6 +18,7 @@ export class SdkClientTocPlugin extends RendererComponent {
12
18
private commandsNavigationItem ?: NavigationItem ;
13
19
private clientsNavigationItem ?: NavigationItem ;
14
20
private paginatorsNavigationItem ?: NavigationItem ;
21
+ private clientDir ?: string ;
15
22
16
23
initialize ( ) {
17
24
// disable existing toc plugin
@@ -57,8 +64,10 @@ export class SdkClientTocPlugin extends RendererComponent {
57
64
model . kindOf ( ReflectionKind . Class ) &&
58
65
model . getFullName ( ) !== "Client" && // Exclude the Smithy Client class.
59
66
( model . name . endsWith ( "Client" ) /* Modular client like S3Client */ ||
60
- ( extendedTypes . length === 1 &&
61
- ( extendedTypes [ 0 ] as ReferenceType ) . name . endsWith ( "Client" ) ) ) /* Legacy client like S3 */
67
+ extendedTypes . filter ( ( reference ) => ( reference as ReferenceType ) . name === `${ model . name } Client` ) . length > 0 ) &&
68
+ /* Filter out other client classes that not sourced from the same directory as current client. e.g. STS, SSO */
69
+ this . clientDir &&
70
+ dirname ( model . sources [ 0 ] ?. file . fullFileName ) === this . clientDir
62
71
) ;
63
72
}
64
73
@@ -93,6 +102,7 @@ export class SdkClientTocPlugin extends RendererComponent {
93
102
buildToc ( model : Reflection , trail : Reflection [ ] , parent : NavigationItem , restriction ?: string [ ] ) {
94
103
const index = trail . indexOf ( model ) ;
95
104
const children = model [ "children" ] || [ ] ;
105
+ if ( ! this . clientDir ) this . clientDir = this . loadClientDir ( model ) ;
96
106
97
107
if ( index < trail . length - 1 && children . length > 40 ) {
98
108
const child = trail [ index + 1 ] ;
@@ -131,4 +141,16 @@ export class SdkClientTocPlugin extends RendererComponent {
131
141
this . commandsNavigationItem ?. children . sort ( ( childA , childB ) => childA . title . localeCompare ( childB . title ) ) ;
132
142
}
133
143
}
144
+
145
+ private loadClientDir ( model : Reflection ) {
146
+ let projectModel = ( model as any ) as ProjectReflection ;
147
+ while ( projectModel . constructor . name !== "ProjectReflection" && ! projectModel . kindOf ( ReflectionKind . SomeModule ) ) {
148
+ projectModel = projectModel . parent as ProjectReflection ;
149
+ }
150
+ const clientsDirectory = ( projectModel as ProjectReflection ) . directory . directories [ "clients" ] . directories ;
151
+ const dir = Object . values ( clientsDirectory ) . filter ( ( directory ) =>
152
+ directory ?. files . find ( ( file ) => file . name . endsWith ( "Client.ts" ) )
153
+ ) [ 0 ] ;
154
+ return dirname ( dir ?. files . find ( ( file ) => file . name . endsWith ( "Client.ts" ) ) . fullFileName ) ;
155
+ }
134
156
}
0 commit comments