@@ -3,8 +3,11 @@ const { normalize, join } = require("path");
33const { copySync, removeSync } = require ( "fs-extra" ) ;
44const { readdirSync, lstatSync, readFileSync, existsSync, writeFileSync } = require ( "fs" ) ;
55
6- const getOverwritablePredicate = ( packageName ) => ( pathName ) => {
7- const overwritablePathnames = [
6+ const getOverwritableDirectories = ( subDirectories , packageName ) => {
7+ const additionalGeneratedFiles = {
8+ "@aws-sdk/client-sts" : [ "defaultRoleAssumers.ts" , "defaultStsRoleAssumers.ts" , "defaultRoleAssumers.spec.ts" ] ,
9+ } ;
10+ const overwritableDirectories = [
811 "commands" ,
912 "models" ,
1013 "protocols" ,
@@ -20,18 +23,18 @@ const getOverwritablePredicate = (packageName) => (pathName) => {
2023 "endpoints.ts" ,
2124 "README.md" ,
2225 ] ;
23- const additionalGeneratedFiles = {
24- "@aws-sdk/client-sts" : [ "defaultRoleAssumers.ts" , "defaultStsRoleAssumers.ts" , "defaultRoleAssumers.spec.ts" ] ,
25- } ;
26- return (
27- pathName
28- . toLowerCase ( )
29- . startsWith (
30- packageName . toLowerCase ( ) . replace ( "@aws-sdk/client-" , "" ) . replace ( "@aws-sdk/aws-" , "" ) . replace ( / - / g , "" )
31- ) ||
32- overwritablePathnames . indexOf ( pathName ) >= 0 ||
33- additionalGeneratedFiles [ packageName . toLowerCase ( ) ] ?. indexOf ( pathName ) >= 0
34- ) ;
26+ return subDirectories . filter ( ( subDirectory ) => {
27+ const isBareBoneClient =
28+ subDirectory . endsWith ( "Client.ts" ) && subDirectories . indexOf ( subDirectory . replace ( "Client.ts" , ".ts" ) ) >= 0 ;
29+ const isAggregateClient =
30+ subDirectory . endsWith ( ".ts" ) && subDirectories . indexOf ( subDirectory . replace ( ".ts" , "Client.ts" ) ) >= 0 ;
31+ return (
32+ isBareBoneClient ||
33+ isAggregateClient ||
34+ overwritableDirectories . indexOf ( subDirectory ) >= 0 ||
35+ additionalGeneratedFiles [ packageName ] ? .indexOf ( subDirectory ) >= 0
36+ ) ;
37+ } ) ;
3538} ;
3639
3740/**
@@ -109,7 +112,6 @@ const copyToClients = async (sourceDir, destinationDir) => {
109112
110113 console . log ( `copying ${ packageName } from ${ artifactPath } to ${ destinationDir } ` ) ;
111114 const destPath = join ( destinationDir , clientName ) ;
112- const overwritablePredicate = getOverwritablePredicate ( packageName ) ;
113115
114116 // Code to move files/folders prefixed with `doc-client-` to `lib/lib-dynamodb`
115117 if ( clientName === "client-dynamodb" ) {
@@ -124,7 +126,9 @@ const copyToClients = async (sourceDir, destinationDir) => {
124126 }
125127 }
126128
127- for ( const packageSub of readdirSync ( artifactPath ) ) {
129+ const packageSubs = readdirSync ( artifactPath ) ;
130+ const overWritableSubs = getOverwritableDirectories ( packageSubs , packageName ) ;
131+ for ( const packageSub of packageSubs ) {
128132 const packageSubPath = join ( artifactPath , packageSub ) ;
129133 const destSubPath = join ( destPath , packageSub ) ;
130134
@@ -141,7 +145,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
141145 } ,
142146 } ;
143147 writeFileSync ( destSubPath , JSON . stringify ( mergedManifest , null , 2 ) . concat ( `\n` ) ) ;
144- } else if ( overwritablePredicate ( packageSub ) || ! existsSync ( destSubPath ) ) {
148+ } else if ( overWritableSubs . includes ( packageSub ) || ! existsSync ( destSubPath ) ) {
145149 if ( lstatSync ( packageSubPath ) . isDirectory ( ) ) removeSync ( destSubPath ) ;
146150 copySync ( packageSubPath , destSubPath , {
147151 overwrite : true ,
@@ -168,9 +172,10 @@ const copyServerTests = async (sourceDir, destinationDir) => {
168172
169173 console . log ( `copying ${ packageName } from ${ artifactPath } to ${ destinationDir } ` ) ;
170174 const destPath = join ( destinationDir , testName ) ;
171- const overwritablePredicate = getOverwritablePredicate ( packageName ) ;
172175
173- for ( const packageSub of readdirSync ( artifactPath ) ) {
176+ const packageSubs = readdirSync ( artifactPath ) ;
177+ const overWritableSubs = getOverwritableDirectories ( packageSubs , packageName ) ;
178+ for ( const packageSub of packageSubs ) {
174179 const packageSubPath = join ( artifactPath , packageSub ) ;
175180 const destSubPath = join ( destPath , packageSub ) ;
176181
@@ -187,7 +192,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
187192 } ,
188193 } ;
189194 writeFileSync ( destSubPath , JSON . stringify ( mergedManifest , null , 2 ) . concat ( `\n` ) ) ;
190- } else if ( overwritablePredicate ( packageSub ) || ! existsSync ( destSubPath ) ) {
195+ } else if ( overWritableSubs . includes ( packageSub ) || ! existsSync ( destSubPath ) ) {
191196 if ( lstatSync ( packageSubPath ) . isDirectory ( ) ) removeSync ( destSubPath ) ;
192197 copySync ( packageSubPath , destSubPath , {
193198 overwrite : true ,
0 commit comments