Skip to content

Commit

Permalink
chore(scripts): update new-client/service-import-equals-with-name
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Oct 17, 2023
1 parent a032d31 commit fdf5603
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import { getServiceImportEqualsOutput } from "./getServiceImportEqualsOutput";
import { CLIENTS_TO_TEST } from "./config";
import { getClientNameWithLocalSuffix } from "./getClientNameWithLocalSuffix";
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageImportEqualsCode } from "./getV3PackageImportEqualsCode";

export const getServiceImportEqualsWithNameOutput = getServiceImportEqualsOutput;
export const getServiceImportEqualsWithNameOutput = () => {
let content = ``;

content += getV3PackageImportEqualsCode(CLIENTS_TO_TEST, { useLocalSuffix: true });
content += "\n";
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST.map(getClientNameWithLocalSuffix));

return content;
};
14 changes: 12 additions & 2 deletions scripts/generateNewClientTests/getV3PackageImportEqualsCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ import {
CLIENT_PACKAGE_NAMES_MAP,
} from "../../src/transforms/v2-to-v3/config";
import { getDefaultLocalName } from "../../src/transforms/v2-to-v3/utils";
import { getClientNameWithLocalSuffix } from "./getClientNameWithLocalSuffix";

export const getV3PackageImportEqualsCode = (clientsToTest: typeof CLIENT_NAMES) => {
export interface V3PackageImportEqualsCodeOptions {
useLocalSuffix?: boolean;
}

export const getV3PackageImportEqualsCode = (
clientsToTest: typeof CLIENT_NAMES,
options?: V3PackageImportEqualsCodeOptions
) => {
let content = ``;
const { useLocalSuffix = false } = options || {};

for (const v2ClientName of clientsToTest) {
const v3ClientDefaultLocalName = getDefaultLocalName(v2ClientName);
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`;
content += `import ${v3ClientDefaultLocalName} = require("${v3ClientPackageName}");\n`;

const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
content += `import ${v3ClientName} = ${[v3ClientDefaultLocalName, v3ClientName].join(".")};\n`;
const importName = useLocalSuffix ? getClientNameWithLocalSuffix(v2ClientName) : v3ClientName;
content += `import ${importName} = ${[v3ClientDefaultLocalName, v3ClientName].join(".")};\n`;
}

return content;
Expand Down

0 comments on commit fdf5603

Please sign in to comment.