@@ -3,39 +3,8 @@ 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 = [
8
- // "commands",
9
- // "models",
10
- // "protocols",
11
- // "pagination",
12
- // "tests",
13
- // "waiters",
14
- // "LICENCE",
15
- // "runtimeConfig.ts",
16
- // "runtimeConfig.browser.ts",
17
- // "runtimeConfig.shared.ts",
18
- // "runtimeConfig.native.ts",
19
- // "index.ts",
20
- // "endpoints.ts",
21
- // "README.md",
22
- // ];
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
- // pathName.endsWith("Client.ts") &&
33
- // overwritablePathnames.indexOf(pathName) >= 0 ||
34
- // additionalGeneratedFiles[packageName.toLowerCase()]?.indexOf(pathName) >= 0
35
- // );
36
- // };
37
- const getOverwritableDirectories = ( subDirectories ) => {
38
- const overwritableDirectories = [
6
+ const getOverwritablePredicate = ( packageName ) => ( pathName ) => {
7
+ const overwritablePathnames = [
39
8
"commands" ,
40
9
"models" ,
41
10
"protocols" ,
@@ -50,17 +19,19 @@ const getOverwritableDirectories = (subDirectories) => {
50
19
"index.ts" ,
51
20
"endpoints.ts" ,
52
21
"README.md" ,
53
- // @aws -sdk/client-sts special files
54
- "defaultRoleAssumers.ts" ,
55
- "defaultStsRoleAssumers.ts" ,
56
- "defaultRoleAssumers.spec.ts" ,
57
22
] ;
58
- return subDirectories . filter ( ( subDirectory ) => {
59
- const isBareBoneClient =
60
- subDirectory . endsWith ( "Client.ts" ) && subDirectories . includes ( subDirectory . replace ( "Client.ts" , ".ts" ) ) ;
61
- const isAggregateClient = subDirectories . includes ( subDirectory . replace ( ".ts" , "Client.ts" ) ) ;
62
- return isBareBoneClient || isAggregateClient || overwritableDirectories . indexOf ( subDirectory ) >= 0 ;
63
- } ) ;
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
+ ) ;
64
35
} ;
65
36
66
37
/**
@@ -138,6 +109,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
138
109
139
110
console . log ( `copying ${ packageName } from ${ artifactPath } to ${ destinationDir } ` ) ;
140
111
const destPath = join ( destinationDir , clientName ) ;
112
+ const overwritablePredicate = getOverwritablePredicate ( packageName ) ;
141
113
142
114
// Code to move files/folders prefixed with `doc-client-` to `lib/lib-dynamodb`
143
115
if ( clientName === "client-dynamodb" ) {
@@ -152,9 +124,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
152
124
}
153
125
}
154
126
155
- const packageSubs = readdirSync ( artifactPath ) ;
156
- const overWritableSubs = getOverwritableDirectories ( packageSubs ) ;
157
- for ( const packageSub of packageSubs ) {
127
+ for ( const packageSub of readdirSync ( artifactPath ) ) {
158
128
const packageSubPath = join ( artifactPath , packageSub ) ;
159
129
const destSubPath = join ( destPath , packageSub ) ;
160
130
@@ -171,7 +141,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
171
141
} ,
172
142
} ;
173
143
writeFileSync ( destSubPath , JSON . stringify ( mergedManifest , null , 2 ) . concat ( `\n` ) ) ;
174
- } else if ( overWritableSubs . includes ( packageSub ) || ! existsSync ( destSubPath ) ) {
144
+ } else if ( overwritablePredicate ( packageSub ) || ! existsSync ( destSubPath ) ) {
175
145
if ( lstatSync ( packageSubPath ) . isDirectory ( ) ) removeSync ( destSubPath ) ;
176
146
copySync ( packageSubPath , destSubPath , {
177
147
overwrite : true ,
@@ -198,10 +168,9 @@ const copyServerTests = async (sourceDir, destinationDir) => {
198
168
199
169
console . log ( `copying ${ packageName } from ${ artifactPath } to ${ destinationDir } ` ) ;
200
170
const destPath = join ( destinationDir , testName ) ;
171
+ const overwritablePredicate = getOverwritablePredicate ( packageName ) ;
201
172
202
- const packageSubs = readdirSync ( artifactPath ) ;
203
- const overWritableSubs = getOverwritableDirectories ( packageSubs ) ;
204
- for ( const packageSub of packageSubs ) {
173
+ for ( const packageSub of readdirSync ( artifactPath ) ) {
205
174
const packageSubPath = join ( artifactPath , packageSub ) ;
206
175
const destSubPath = join ( destPath , packageSub ) ;
207
176
@@ -218,7 +187,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
218
187
} ,
219
188
} ;
220
189
writeFileSync ( destSubPath , JSON . stringify ( mergedManifest , null , 2 ) . concat ( `\n` ) ) ;
221
- } else if ( overWritableSubs . includes ( packageSub ) || ! existsSync ( destSubPath ) ) {
190
+ } else if ( overwritablePredicate ( packageSub ) || ! existsSync ( destSubPath ) ) {
222
191
if ( lstatSync ( packageSubPath ) . isDirectory ( ) ) removeSync ( destSubPath ) ;
223
192
copySync ( packageSubPath , destSubPath , {
224
193
overwrite : true ,
0 commit comments