Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions codegen/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
* permissions and limitations under the License.
*/

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.gradle.tasks.SmithyBuild
import software.amazon.smithy.aws.traits.ServiceTrait
import kotlin.streams.toList

buildscript {
dependencies {
"classpath"("software.amazon.smithy:smithy-aws-traits:[1.5.1,2.0.0[")
}
}

plugins {
id("software.amazon.smithy") version "0.5.3"
Expand Down Expand Up @@ -44,8 +54,24 @@ tasks.register("generate-smithy-build") {
val modelsDirProp: String by project
val models = project.file(modelsDirProp);

fileTree(models).filter { it.isFile }.files.forEach { file ->
val (sdkId, version, remaining) = file.name.split(".")
fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file ->
val model = Model.assembler()
.addImport(file.absolutePath)
.assemble().result.get();
val services = model.shapes(ServiceShape::class.javaObjectType).sorted().toList();
if (services.size != 1) {
throw Exception("There must be exactly one service in each aws model file, but found " +
"${services.size} in ${file.name}: ${services.map { it.id }}");
}
val service = services[0]

val serviceTrait = service.getTrait(ServiceTrait::class.javaObjectType).get();

val sdkId = serviceTrait.sdkId
.replace(" ", "-")
.toLowerCase();
val version = service.version.toLowerCase();

val clientName = sdkId.split("-").toTypedArray()
.map { it.capitalize() }
.joinToString(separator = " ")
Expand All @@ -59,7 +85,7 @@ tasks.register("generate-smithy-build") {
.withMember("typescript-codegen", Node.objectNodeBuilder()
.withMember("package", "@aws-sdk/client-" + sdkId.toLowerCase())
// Note that this version is replaced by Lerna when publishing.
.withMember("packageVersion", "1.0.0-rc.1")
.withMember("packageVersion", "3.0.0")
.withMember("packageJson", manifestOverwrites)
.withMember("packageDescription", "AWS SDK for JavaScript "
+ clientName + " Client for Node.js, Browser and React Native")
Expand Down
18 changes: 13 additions & 5 deletions scripts/generate-clients/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const { prettifyCode } = require("./code-prettify");
const SDK_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "clients"));
const PROTOCOL_TESTS_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "protocol_tests"));

const { models, globs, output: clientsDir } = yargs
const {
models,
globs,
output: clientsDir,
noProtocolTest,
} = yargs
.alias("m", "models")
.string("m")
.describe("m", "The path to directory with models.")
Expand All @@ -26,21 +31,24 @@ const { models, globs, output: clientsDir } = yargs
.string("o")
.describe("o", "The output directory for built clients")
.default("o", SDK_CLIENTS_DIR)
.alias("n", "noProtocolTest")
.boolean("n")
.describe("n", "Disable generating protocol test files")
.help().argv;

(async () => {
try {
await generateClients(models || globs);
await generateProtocolTests();
if (!noProtocolTest) await generateProtocolTests();

await prettifyCode(CODE_GEN_SDK_OUTPUT_DIR);
await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
if (!noProtocolTest) await prettifyCode(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);

await copyToClients(CODE_GEN_SDK_OUTPUT_DIR, clientsDir);
await copyToClients(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR);
if (!noProtocolTest) await copyToClients(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR, PROTOCOL_TESTS_CLIENTS_DIR);

emptyDirSync(CODE_GEN_SDK_OUTPUT_DIR);
emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
if (!noProtocolTest) emptyDirSync(CODE_GEN_PROTOCOL_TESTS_OUTPUT_DIR);
emptyDirSync(TEMP_CODE_GEN_INPUT_DIR);

rmdirSync(TEMP_CODE_GEN_INPUT_DIR);
Expand Down