Skip to content

Commit

Permalink
feat(type-safe-api): platform agnostic copies for gradle wrapper and …
Browse files Browse the repository at this point in the history
…smithy transformer

Rewrite the copy scripts in TypeScript instead of bash, and move as subcommands of the type-safe-api
script. This is now more consistent with the other scripts, and has the advantage of being platform
agnostic via node.
  • Loading branch information
cogwirrel committed Oct 18, 2024
1 parent 174a093 commit 4a2ed79
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 115 deletions.
6 changes: 0 additions & 6 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions packages/pdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions packages/type-safe-api/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
import * as fs from "fs";
import * as path from "path";

const GRADLE_WRAPPER_DIR = "gradle/wrapper";

const copyFromScriptDir = (rootScriptDir: string, file: string) => {
if (!fs.existsSync(file)) {
fs.copyFileSync(path.join(rootScriptDir, "custom", "gradle-wrapper", file), file);
}
}

export default async (_argv: string[], rootScriptDir: string) => {
// Create the gradle wrapper directory if it doesn't already exist
fs.mkdirSync(GRADLE_WRAPPER_DIR, { recursive: true });

// Copy the gradle wrapper files into the working directory
[
path.join(GRADLE_WRAPPER_DIR, "gradle-wrapper.jar"),
path.join(GRADLE_WRAPPER_DIR, "gradle-wrapper.properties"),
"gradlew",
"gradlew.bat",
].forEach((file) => copyFromScriptDir(rootScriptDir, file));
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
import * as fs from "fs";
import * as path from "path";

const SMITHY_ASYNC_DIR = ".smithy-async";
const JAR_NAME = "aws-pdk-smithy-async-transformer.jar";

export default async (_argv: string[], rootScriptDir: string) => {
// Create the smithy transformer dir
fs.mkdirSync(SMITHY_ASYNC_DIR, { recursive: true });

// Copy the jar if it doesn't already exist
const sourceJarPath = path.join(rootScriptDir, "custom", "smithy-async-transformer", JAR_NAME);
const destinationJarPath = path.join(SMITHY_ASYNC_DIR, JAR_NAME);

if (!fs.existsSync(destinationJarPath)) {
fs.copyFileSync(sourceJarPath, destinationJarPath);
}
};
10 changes: 9 additions & 1 deletion packages/type-safe-api/scripts/type-safe-api/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import generateMockData from "./custom/mock-data/generate-mock-data";
import parseOpenapiSpec from "./parser/parse-openapi-spec";
import generate from "./generators/generate-next";
import generateAsyncapiSpec from "./custom/generate-asyncapi-spec/generate-asyncapi-spec";
import copyGradleWrapper from "./custom/gradle-wrapper/copy-gradle-wrapper";
import copyAsyncSmithyTransformer from "./custom/smithy-async-transformer/copy-transformer";
import * as path from "path";

interface SubCommandArgs {
Expand All @@ -17,6 +19,8 @@ void (async () => {

const argv = (subCommandArgs as any)._unknown as string[];

const rootScriptDir = path.resolve(__dirname);

switch (subCommandArgs.command) {
case "generate-mock-data":
return await generateMockData(argv);
Expand All @@ -25,7 +29,11 @@ void (async () => {
case "generate-asyncapi-spec":
return await generateAsyncapiSpec(argv);
case "generate":
return await generate(argv, path.resolve(__dirname));
return await generate(argv, rootScriptDir);
case "copy-gradle-wrapper":
return await copyGradleWrapper(argv, rootScriptDir);
case "copy-async-smithy-transformer":
return await copyAsyncSmithyTransformer(argv, rootScriptDir);
default:
throw new Error(`Unknown subcommand ${subCommandArgs.command}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export enum TypeSafeApiScript {
GENERATE_NEXT = "type-safe-api generate",
GENERATE_MOCK_DATA = "type-safe-api generate-mock-data",
CLEAN_OPENAPI_GENERATED_CODE = "type-safe-api.clean-openapi-generated-code",
COPY_GRADLE_WRAPPER = "type-safe-api.copy-gradle-wrapper",
COPY_ASYNC_SMITHY_TRANSFORMER = "type-safe-api.copy-async-smithy-transformer",
COPY_GRADLE_WRAPPER = "type-safe-api copy-gradle-wrapper",
COPY_ASYNC_SMITHY_TRANSFORMER = "type-safe-api copy-async-smithy-transformer",
GENERATE_ASYNCAPI_SPEC = "type-safe-api generate-asyncapi-spec",
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a2ed79

Please sign in to comment.