|
| 1 | +/* |
| 2 | + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import software.amazon.smithy.model.node.Node |
| 17 | +import software.amazon.smithy.gradle.tasks.SmithyBuild |
| 18 | + |
| 19 | +plugins { |
| 20 | + id("software.amazon.smithy") version "0.4.1" |
| 21 | +} |
| 22 | + |
| 23 | +dependencies { |
| 24 | + compile(project(":smithy-aws-typescript-codegen")) |
| 25 | +} |
| 26 | + |
| 27 | +// This project doesn't produce a JAR. |
| 28 | +tasks["jar"].enabled = false |
| 29 | + |
| 30 | +// Run the SmithyBuild task manually since this project needs the built JAR |
| 31 | +// from smithy-aws-typescript-codegen. |
| 32 | +tasks["smithyBuildJar"].enabled = false |
| 33 | + |
| 34 | +tasks.create<SmithyBuild>("buildSdk") { |
| 35 | + addRuntimeClasspath = true |
| 36 | +} |
| 37 | + |
| 38 | +// Generates a smithy-build.json file by creating a new projection for every |
| 39 | +// JSON file found in aws-models/. The generated smithy-build.json file is |
| 40 | +// not committed to git since it's rebuilt each time codegen is performed. |
| 41 | +tasks.register("generate-smithy-build") { |
| 42 | + doLast { |
| 43 | + val projectionsBuilder = Node.objectNodeBuilder() |
| 44 | + |
| 45 | + fileTree("aws-models").filter { it.isFile }.files.forEach { file -> |
| 46 | + val (sdkId, version, remaining) = file.name.split(".") |
| 47 | + val projectionContents = Node.objectNodeBuilder() |
| 48 | + .withMember("imports", Node.fromStrings("aws-models/" + file.name)) |
| 49 | + .withMember("plugins", Node.objectNode() |
| 50 | + .withMember("typescript-codegen", Node.objectNodeBuilder() |
| 51 | + .withMember("package", "@aws-sdk/client-" + sdkId.toLowerCase()) |
| 52 | + // Note that this version is replaced by Lerna when publishing. |
| 53 | + .withMember("packageVersion", "1.0.0") |
| 54 | + .build())) |
| 55 | + .build() |
| 56 | + projectionsBuilder.withMember(sdkId + "." + version.toLowerCase(), projectionContents) |
| 57 | + } |
| 58 | + |
| 59 | + file("smithy-build.json").writeText(Node.prettyPrintJson(Node.objectNodeBuilder() |
| 60 | + .withMember("version", "1.0") |
| 61 | + .withMember("projections", projectionsBuilder.build()) |
| 62 | + .build())) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +// Run the `buildSdk` automatically. |
| 67 | +tasks["build"] |
| 68 | + .dependsOn(tasks["generate-smithy-build"]) |
| 69 | + .finalizedBy(tasks["buildSdk"]) |
0 commit comments