@@ -3,8 +3,11 @@ const { normalize, join } = require("path");
3
3
const { copySync, removeSync } = require ( "fs-extra" ) ;
4
4
const { readdirSync, lstatSync, readFileSync, existsSync, writeFileSync } = require ( "fs" ) ;
5
5
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 = [
8
11
"commands" ,
9
12
"models" ,
10
13
"protocols" ,
@@ -20,18 +23,17 @@ const getOverwritablePredicate = (packageName) => (pathName) => {
20
23
"endpoints.ts" ,
21
24
"README.md" ,
22
25
] ;
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 . includes ( subDirectory . replace ( "Client.ts" , ".ts" ) ) ;
29
+ const isAggregateClient = subDirectories . includes ( subDirectory . replace ( ".ts" , "Client.ts" ) ) ;
30
+ return (
31
+ isBareBoneClient ||
32
+ isAggregateClient ||
33
+ overwritableDirectories . indexOf ( subDirectory ) >= 0 ||
34
+ additionalGeneratedFiles [ packageName ] . includes ( subDirectory )
35
+ ) ;
36
+ } ) ;
35
37
} ;
36
38
37
39
/**
@@ -109,7 +111,6 @@ const copyToClients = async (sourceDir, destinationDir) => {
109
111
110
112
console . log ( `copying ${ packageName } from ${ artifactPath } to ${ destinationDir } ` ) ;
111
113
const destPath = join ( destinationDir , clientName ) ;
112
- const overwritablePredicate = getOverwritablePredicate ( packageName ) ;
113
114
114
115
// Code to move files/folders prefixed with `doc-client-` to `lib/lib-dynamodb`
115
116
if ( clientName === "client-dynamodb" ) {
@@ -124,7 +125,9 @@ const copyToClients = async (sourceDir, destinationDir) => {
124
125
}
125
126
}
126
127
127
- for ( const packageSub of readdirSync ( artifactPath ) ) {
128
+ const packageSubs = readdirSync ( artifactPath ) ;
129
+ const overWritableSubs = getOverwritableDirectories ( packageSubs , packageName ) ;
130
+ for ( const packageSub of packageSubs ) {
128
131
const packageSubPath = join ( artifactPath , packageSub ) ;
129
132
const destSubPath = join ( destPath , packageSub ) ;
130
133
@@ -141,7 +144,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
141
144
} ,
142
145
} ;
143
146
writeFileSync ( destSubPath , JSON . stringify ( mergedManifest , null , 2 ) . concat ( `\n` ) ) ;
144
- } else if ( overwritablePredicate ( packageSub ) || ! existsSync ( destSubPath ) ) {
147
+ } else if ( overWritableSubs . includes ( packageSub ) || ! existsSync ( destSubPath ) ) {
145
148
if ( lstatSync ( packageSubPath ) . isDirectory ( ) ) removeSync ( destSubPath ) ;
146
149
copySync ( packageSubPath , destSubPath , {
147
150
overwrite : true ,
@@ -168,9 +171,10 @@ const copyServerTests = async (sourceDir, destinationDir) => {
168
171
169
172
console . log ( `copying ${ packageName } from ${ artifactPath } to ${ destinationDir } ` ) ;
170
173
const destPath = join ( destinationDir , testName ) ;
171
- const overwritablePredicate = getOverwritablePredicate ( packageName ) ;
172
174
173
- for ( const packageSub of readdirSync ( artifactPath ) ) {
175
+ const packageSubs = readdirSync ( artifactPath ) ;
176
+ const overWritableSubs = getOverwritableDirectories ( packageSubs , packageName ) ;
177
+ for ( const packageSub of packageSubs ) {
174
178
const packageSubPath = join ( artifactPath , packageSub ) ;
175
179
const destSubPath = join ( destPath , packageSub ) ;
176
180
@@ -187,7 +191,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
187
191
} ,
188
192
} ;
189
193
writeFileSync ( destSubPath , JSON . stringify ( mergedManifest , null , 2 ) . concat ( `\n` ) ) ;
190
- } else if ( overwritablePredicate ( packageSub ) || ! existsSync ( destSubPath ) ) {
194
+ } else if ( overWritableSubs . includes ( packageSub ) || ! existsSync ( destSubPath ) ) {
191
195
if ( lstatSync ( packageSubPath ) . isDirectory ( ) ) removeSync ( destSubPath ) ;
192
196
copySync ( packageSubPath , destSubPath , {
193
197
overwrite : true ,
0 commit comments