Skip to content

Commit cb457de

Browse files
authored
chore: revert script change (#2614)
1 parent 5eca565 commit cb457de

File tree

2 files changed

+21
-52
lines changed

2 files changed

+21
-52
lines changed

scripts/generate-clients/copy-to-clients.js

+20-51
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,8 @@ const { normalize, join } = require("path");
33
const { copySync, removeSync } = require("fs-extra");
44
const { readdirSync, lstatSync, readFileSync, existsSync, writeFileSync } = require("fs");
55

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 = [
398
"commands",
409
"models",
4110
"protocols",
@@ -50,17 +19,19 @@ const getOverwritableDirectories = (subDirectories) => {
5019
"index.ts",
5120
"endpoints.ts",
5221
"README.md",
53-
// @aws-sdk/client-sts special files
54-
"defaultRoleAssumers.ts",
55-
"defaultStsRoleAssumers.ts",
56-
"defaultRoleAssumers.spec.ts",
5722
];
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+
);
6435
};
6536

6637
/**
@@ -138,6 +109,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
138109

139110
console.log(`copying ${packageName} from ${artifactPath} to ${destinationDir}`);
140111
const destPath = join(destinationDir, clientName);
112+
const overwritablePredicate = getOverwritablePredicate(packageName);
141113

142114
// Code to move files/folders prefixed with `doc-client-` to `lib/lib-dynamodb`
143115
if (clientName === "client-dynamodb") {
@@ -152,9 +124,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
152124
}
153125
}
154126

155-
const packageSubs = readdirSync(artifactPath);
156-
const overWritableSubs = getOverwritableDirectories(packageSubs);
157-
for (const packageSub of packageSubs) {
127+
for (const packageSub of readdirSync(artifactPath)) {
158128
const packageSubPath = join(artifactPath, packageSub);
159129
const destSubPath = join(destPath, packageSub);
160130

@@ -171,7 +141,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
171141
},
172142
};
173143
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
174-
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
144+
} else if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) {
175145
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
176146
copySync(packageSubPath, destSubPath, {
177147
overwrite: true,
@@ -198,10 +168,9 @@ const copyServerTests = async (sourceDir, destinationDir) => {
198168

199169
console.log(`copying ${packageName} from ${artifactPath} to ${destinationDir}`);
200170
const destPath = join(destinationDir, testName);
171+
const overwritablePredicate = getOverwritablePredicate(packageName);
201172

202-
const packageSubs = readdirSync(artifactPath);
203-
const overWritableSubs = getOverwritableDirectories(packageSubs);
204-
for (const packageSub of packageSubs) {
173+
for (const packageSub of readdirSync(artifactPath)) {
205174
const packageSubPath = join(artifactPath, packageSub);
206175
const destSubPath = join(destPath, packageSub);
207176

@@ -218,7 +187,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
218187
},
219188
};
220189
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
221-
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
190+
} else if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) {
222191
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
223192
copySync(packageSubPath, destSubPath, {
224193
overwrite: true,

scripts/generate-clients/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const {
4848
await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
4949
await copyServerTests(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR);
5050

51-
// emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
51+
emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
5252
emptyDirSync(TEMP_CODE_GEN_INPUT_DIR);
5353

5454
rmdirSync(TEMP_CODE_GEN_INPUT_DIR);

0 commit comments

Comments
 (0)