Skip to content

Commit 6b758ab

Browse files
committed
chore(geneate-clients): copy client with diff name to folder
1 parent cb457de commit 6b758ab

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ 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 = [
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,17 @@ 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.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+
});
3537
};
3638

3739
/**
@@ -109,7 +111,6 @@ const copyToClients = async (sourceDir, destinationDir) => {
109111

110112
console.log(`copying ${packageName} from ${artifactPath} to ${destinationDir}`);
111113
const destPath = join(destinationDir, clientName);
112-
const overwritablePredicate = getOverwritablePredicate(packageName);
113114

114115
// Code to move files/folders prefixed with `doc-client-` to `lib/lib-dynamodb`
115116
if (clientName === "client-dynamodb") {
@@ -124,7 +125,9 @@ const copyToClients = async (sourceDir, destinationDir) => {
124125
}
125126
}
126127

127-
for (const packageSub of readdirSync(artifactPath)) {
128+
const packageSubs = readdirSync(artifactPath);
129+
const overWritableSubs = getOverwritableDirectories(packageSubs, packageName);
130+
for (const packageSub of packageSubs) {
128131
const packageSubPath = join(artifactPath, packageSub);
129132
const destSubPath = join(destPath, packageSub);
130133

@@ -141,7 +144,7 @@ const copyToClients = async (sourceDir, destinationDir) => {
141144
},
142145
};
143146
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
144-
} else if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) {
147+
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
145148
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
146149
copySync(packageSubPath, destSubPath, {
147150
overwrite: true,
@@ -168,9 +171,10 @@ const copyServerTests = async (sourceDir, destinationDir) => {
168171

169172
console.log(`copying ${packageName} from ${artifactPath} to ${destinationDir}`);
170173
const destPath = join(destinationDir, testName);
171-
const overwritablePredicate = getOverwritablePredicate(packageName);
172174

173-
for (const packageSub of readdirSync(artifactPath)) {
175+
const packageSubs = readdirSync(artifactPath);
176+
const overWritableSubs = getOverwritableDirectories(packageSubs, packageName);
177+
for (const packageSub of packageSubs) {
174178
const packageSubPath = join(artifactPath, packageSub);
175179
const destSubPath = join(destPath, packageSub);
176180

@@ -187,7 +191,7 @@ const copyServerTests = async (sourceDir, destinationDir) => {
187191
},
188192
};
189193
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
190-
} else if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) {
194+
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
191195
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
192196
copySync(packageSubPath, destSubPath, {
193197
overwrite: true,

scripts/generate-clients/index.js

Lines changed: 1 addition & 1 deletion
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)