From 20b41ae0964909a0927bd525df5fb847db5f665d Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Thu, 12 Dec 2019 16:24:26 -0800 Subject: [PATCH 1/4] chore: generate package static components from templates --- package.json | 1 + scripts/generate-clients/code-gen.js | 6 +- scripts/generate-clients/copy-to-clients.js | 107 ++++++---- .../templates/.gitignore.sample | 14 ++ .../templates/.npmignore.sample | 4 + .../generate-clients/templates/LICENSE.sample | 201 ++++++++++++++++++ .../templates/README.md.sample | 6 + .../templates/package.json.sample | 41 ++++ .../templates/tsconfig.es.json.sample | 18 ++ .../templates/tsconfig.json.sample | 28 +++ yarn.lock | 123 ++++++++++- 11 files changed, 506 insertions(+), 43 deletions(-) create mode 100644 scripts/generate-clients/templates/.gitignore.sample create mode 100644 scripts/generate-clients/templates/.npmignore.sample create mode 100644 scripts/generate-clients/templates/LICENSE.sample create mode 100644 scripts/generate-clients/templates/README.md.sample create mode 100644 scripts/generate-clients/templates/package.json.sample create mode 100644 scripts/generate-clients/templates/tsconfig.es.json.sample create mode 100644 scripts/generate-clients/templates/tsconfig.json.sample diff --git a/package.json b/package.json index cac7e517d554..ae48fdc9a859 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "cucumber": "0.5.x", "fs-extra": "^8.1.0", "generate-changelog": "^1.7.1", + "handlebars": "^4.5.3", "husky": "^3.0.0", "jest": "^24.7.1", "jmespath": "^0.15.0", diff --git a/scripts/generate-clients/code-gen.js b/scripts/generate-clients/code-gen.js index 256c0756d68d..81ad87a2c4e2 100644 --- a/scripts/generate-clients/code-gen.js +++ b/scripts/generate-clients/code-gen.js @@ -13,7 +13,8 @@ const CODE_GEN_ROOT = path.normalize( async function generateClients(models) { console.info("models directory: ", models); if (models === CODE_GEN_INPUT_DIR) { - // console.log("skipping copying models to codegen directory"); + // This script will clean the CODE_GEN_INPUT_DIR in execution. + // throw to avoid input model being removed throw new Error( `models directory cannot be the same as ${CODE_GEN_INPUT_DIR}` ); @@ -21,9 +22,6 @@ async function generateClients(models) { console.log(`clearing code gen input folder...`); emptyDirSync(CODE_GEN_INPUT_DIR); console.log(`copying models from ${models} to ${CODE_GEN_INPUT_DIR}...`); - // copySync(models, CODE_GEN_INPUT_DIR, { - // overwrite: true - // }); for (const modelFileName of readdirSync(models)) { const modelPath = path.join(models, modelFileName); if (!lstatSync(modelPath).isFile()) continue; diff --git a/scripts/generate-clients/copy-to-clients.js b/scripts/generate-clients/copy-to-clients.js index 10f61c6236ab..638cfa7e8311 100644 --- a/scripts/generate-clients/copy-to-clients.js +++ b/scripts/generate-clients/copy-to-clients.js @@ -1,5 +1,6 @@ -const path = require("path"); +const { join, normalize } = require("path"); const { copySync, ensureDirSync } = require("fs-extra"); +const handlebars = require("handlebars"); const { readdirSync, lstatSync, @@ -8,8 +9,8 @@ const { writeFileSync } = require("fs"); -const CODE_GEN_OUTPUT_DIR = path.normalize( - path.join( +const CODE_GEN_OUTPUT_DIR = normalize( + join( __dirname, "..", "..", @@ -21,64 +22,77 @@ const CODE_GEN_OUTPUT_DIR = path.normalize( ) ); -const unOverridables = [ - "package.json", - "tsconfig.es.json", - "tsconfig.json", - "tsconfig.test.json" -]; +/** + * templates are a black list of files we don't want codegen artifact + * to override in the clients folder + */ +const templates = readdirSync(join(__dirname, "templates")) + .filter(name => /.sample$/.test(name)) + .reduce((accumulator, curr) => { + const templatePath = join(__dirname, "templates", curr); + const template = readFileSync(templatePath).toString(); + accumulator[curr.replace(/.sample$/, "")] = template; + return accumulator; + }, {}); async function copyToClients(clientsDir) { for (const modelName of readdirSync(CODE_GEN_OUTPUT_DIR)) { if (modelName === "source") continue; - const artifactPath = path.join( + const artifactPath = join( CODE_GEN_OUTPUT_DIR, modelName, "typescript-codegen" ); - const packageManifestPath = path.join(artifactPath, "package.json"); + const packageManifestPath = join(artifactPath, "package.json"); if (!existsSync(packageManifestPath)) { console.error(`${modelName} generates empty client, skip.`); continue; } + const packageManifest = JSON.parse( readFileSync(packageManifestPath).toString() ); - const packageName = packageManifest.name.replace("@aws-sdk/", ""); + const packageName = packageManifest.name; console.log(`copying ${packageName} from ${artifactPath} to ${clientsDir}`); - const destPath = path.join(clientsDir, packageName); - for (const packageSub of readdirSync(artifactPath)) { - const packageSubPath = path.join(artifactPath, packageSub); - const destSubPath = path.join(destPath, packageSub); - if (unOverridables.indexOf(packageSub) >= 0) { - if (!existsSync(destSubPath)) - copySync(packageSubPath, destSubPath, { overwrite: true }); - else if (packageSub === "package.json") { + const destPath = join(clientsDir, packageName.replace("@aws-sdk/", "")); + + //Data used to generate files from template + const templateData = { + year: new Date().getFullYear(), + packageName + }; + + for (const packageSub of [ + ...readdirSync(artifactPath), + ...Object.keys(templates) + ]) { + const packageSubPath = join(artifactPath, packageSub); + const destSubPath = join(destPath, packageSub); + + if (Object.keys(templates).indexOf(packageSub) >= 0) { + if (packageSub === "package.json") { /** * Copy package.json content in detail. * Basically merge the generated package.json and dest package.json * but prefer the values from dest when they contain the same key * */ - const destManifest = JSON.parse(readFileSync(destSubPath).toString()); - const updatedManifest = { - ...packageManifest, - ...destManifest, - scripts: { - ...packageManifest.scripts, - ...destManifest.scripts - }, - dependencies: { - ...packageManifest.dependencies, - ...destManifest.dependencies - }, - devDependencies: { - ...packageManifest.devDependencies, - ...destManifest.devDependencies - } - }; + const destManifest = JSON.parse( + existsSync(destSubPath) + ? readFileSync(destSubPath).toString() + : handlebars.compile(templates[packageSub])(templateData) + ); + const updatedManifest = mergeManifest(packageManifest, destManifest); writeFileSync(destSubPath, JSON.stringify(updatedManifest, null, 2)); + } else if (!existsSync(destSubPath)) { + //for files not yet exists and we have a template for it; generate from template + const file = handlebars.compile(templates[packageSub])(templateData); + writeFileSync(destSubPath, file); + } else { + //for files we have template but we already have a new version in clients folder, always prefer current one + //PASS } } else { + //For things not in codegen artifact black list, overwrite the existing ones. if (lstatSync(packageSubPath).isDirectory()) ensureDirSync(destSubPath); copySync(packageSubPath, destSubPath, { overwrite: true }); } @@ -86,4 +100,23 @@ async function copyToClients(clientsDir) { } } +const mergeManifest = (source, dest) => { + return { + ...source, + ...dest, + scripts: { + ...source.scripts, + ...dest.scripts + }, + dependencies: { + ...source.dependencies, + ...dest.dependencies + }, + devDependencies: { + ...source.devDependencies, + ...dest.devDependencies + } + }; +}; + module.exports = { copyToClients, CODE_GEN_OUTPUT_DIR }; diff --git a/scripts/generate-clients/templates/.gitignore.sample b/scripts/generate-clients/templates/.gitignore.sample new file mode 100644 index 000000000000..2a98e39826ad --- /dev/null +++ b/scripts/generate-clients/templates/.gitignore.sample @@ -0,0 +1,14 @@ +/node_modules/ +/build/ +/coverage/ +/docs/ +/types/ +/dist/ +*.tsbuildinfo +*.tgz +*.log +package-lock.json + +*.d.ts +*.js +*.js.map \ No newline at end of file diff --git a/scripts/generate-clients/templates/.npmignore.sample b/scripts/generate-clients/templates/.npmignore.sample new file mode 100644 index 000000000000..9bda6bbaa691 --- /dev/null +++ b/scripts/generate-clients/templates/.npmignore.sample @@ -0,0 +1,4 @@ +/coverage/ +/docs/ +tsconfig.test.json +*.tsbuildinfo \ No newline at end of file diff --git a/scripts/generate-clients/templates/LICENSE.sample b/scripts/generate-clients/templates/LICENSE.sample new file mode 100644 index 000000000000..e7bd4e8b4d20 --- /dev/null +++ b/scripts/generate-clients/templates/LICENSE.sample @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {{year}} Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/scripts/generate-clients/templates/README.md.sample b/scripts/generate-clients/templates/README.md.sample new file mode 100644 index 000000000000..81fe125ea655 --- /dev/null +++ b/scripts/generate-clients/templates/README.md.sample @@ -0,0 +1,6 @@ +{{packageName}} + +[![NPM version](https://img.shields.io/npm/v/{{packageName}}/preview.svg)](https://www.npmjs.com/package/{{packageName}}) +[![NPM downloads](https://img.shields.io/npm/dm/{{packageName}}.svg)](https://www.npmjs.com/package/{{packageName}}) + +For SDK usage, please step to [SDK reademe](https://github.com/aws/aws-sdk-js-v3). diff --git a/scripts/generate-clients/templates/package.json.sample b/scripts/generate-clients/templates/package.json.sample new file mode 100644 index 000000000000..15d138d6a0ba --- /dev/null +++ b/scripts/generate-clients/templates/package.json.sample @@ -0,0 +1,41 @@ +{ + "version": "0.1.0-preview.3", + "scripts": { + "clean": "npm run remove-definitions && npm run remove-dist && npm run remove-js && npm run remove-maps", + "build-documentation": "npm run clean && typedoc ./", + "prepublishOnly": "yarn build", + "pretest": "tsc", + "remove-definitions": "rimraf ./types", + "remove-dist": "rimraf ./dist", + "remove-documentation": "rimraf ./docs", + "remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./lib/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js", + "remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./lib/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map", + "build:es": "tsc -p tsconfig.es.json", + "build": "yarn pretest && yarn build:es" + }, + "main": "./dist/cjs/index.js", + "types": "./types/index.d.ts", + "author": { + "name": "AWS SDK for JavaScript Team", + "url": "https://aws.amazon.com/javascript/" + }, + "module": "./dist/es/index.js", + "browser": { + "./runtimeConfig": "./runtimeConfig.browser" + }, + "sideEffects": false, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^1.8.0" + }, + "devDependencies": { + "@aws-sdk/client-documentation-generator": "^0.1.0-preview.3", + "@types/node": "^10.0.0", + "rimraf": "^3.0.0", + "typedoc": "^0.15.0", + "typescript": "^3.7.0" + }, + "engines": { + "node": ">=8.0.0" + } +} diff --git a/scripts/generate-clients/templates/tsconfig.es.json.sample b/scripts/generate-clients/templates/tsconfig.es.json.sample new file mode 100644 index 000000000000..60e5ef3e90cd --- /dev/null +++ b/scripts/generate-clients/templates/tsconfig.es.json.sample @@ -0,0 +1,18 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "target": "es5", + "module": "esnext", + "moduleResolution": "node", + "declaration": false, + "declarationDir": null, + "lib": [ + "es5", + "es2015.promise", + "es2015.collection", + "es2015.iterable", + "es2015.symbol.wellknown" + ], + "outDir": "dist/es" + } +} diff --git a/scripts/generate-clients/templates/tsconfig.json.sample b/scripts/generate-clients/templates/tsconfig.json.sample new file mode 100644 index 000000000000..181286d5daef --- /dev/null +++ b/scripts/generate-clients/templates/tsconfig.json.sample @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "alwaysStrict": true, + "target": "es2017", + "module": "commonjs", + "declaration": true, + "strict": true, + "sourceMap": true, + "downlevelIteration": true, + "importHelpers": true, + "noEmitHelpers": true, + "incremental": true, + "resolveJsonModule": true, + "noUnusedLocals": true, + "declarationDir": "./types", + "outDir": "dist/cjs" + }, + "typedocOptions": { + "exclude": "**/node_modules/**", + "excludedNotExported": true, + "excludePrivate": true, + "hideGenerator": true, + "ignoreCompilerErrors": true, + "mode": "file", + "out": "./docs", + "plugin": "@aws-sdk/client-documentation-generator" + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 1fc0ca55aa86..b999a6d3a49e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -55,6 +55,15 @@ dependencies: tslib "^1.9.3" +"@aws-sdk/apply-body-checksum-middleware@^0.1.0-preview.5": + version "0.1.0-preview.8" + resolved "https://registry.yarnpkg.com/@aws-sdk/apply-body-checksum-middleware/-/apply-body-checksum-middleware-0.1.0-preview.8.tgz#19a37c810c7f5f00cb5f4d194ad167b5b5b0aa81" + integrity sha512-UoK128Kum26NYuOfnG1vVjfFfYBy7m8bIkBYlORwrGYLHawUwaxan8MTCrk4P/XSlYm0NsyAicAVDvAeGWSZXA== + dependencies: + "@aws-sdk/is-array-buffer" "^0.1.0-preview.3" + "@aws-sdk/types" "^0.1.0-preview.7" + tslib "^1.8.0" + "@aws-sdk/client-cognito-identity-browser@^0.1.0-preview.7": version "0.1.0-preview.7" resolved "https://registry.yarnpkg.com/@aws-sdk/client-cognito-identity-browser/-/client-cognito-identity-browser-0.1.0-preview.7.tgz#05ef31ec3e8fa0e57c27032a320ead2cdd8db32b" @@ -123,6 +132,14 @@ "@aws-sdk/xml-body-parser" "^0.1.0-preview.6" tslib "^1.8.0" +"@aws-sdk/location-constraint-middleware@^0.1.0-preview.5": + version "0.1.0-preview.7" + resolved "https://registry.yarnpkg.com/@aws-sdk/location-constraint-middleware/-/location-constraint-middleware-0.1.0-preview.7.tgz#0ae88632dc37187b95242e8a0370b345745b3a48" + integrity sha512-K7EZ77oSVqyrTDZKJ8OQ7m1/EAEoRFUknE0HsiTRImhRHqxPhR+sP6brWU+gdywgYbDVaXJox30GUMNAOqhs9Q== + dependencies: + "@aws-sdk/types" "^0.1.0-preview.7" + tslib "^1.8.0" + "@aws-sdk/middleware-serializer@^0.1.0-preview.5": version "0.1.0-preview.5" resolved "https://registry.yarnpkg.com/@aws-sdk/middleware-serializer/-/middleware-serializer-0.1.0-preview.5.tgz#00a8355abc462679580d49969eea8c8513ce4208" @@ -160,6 +177,19 @@ "@aws-sdk/types" "^0.1.0-preview.5" tslib "^1.8.0" +"@aws-sdk/ssec-middleware@^0.1.0-preview.5": + version "0.1.0-preview.8" + resolved "https://registry.yarnpkg.com/@aws-sdk/ssec-middleware/-/ssec-middleware-0.1.0-preview.8.tgz#d82764bbb1fa4397711ee74f4625be20a86c52f5" + integrity sha512-vDxnda94Wp2M1RXQXPJYedDwNt9sAN2j+N6QvDpwOZ2G2qEVLOvkPPTEz2GwzU6dTQY3HSd/Psomz+9OeamWtA== + dependencies: + "@aws-sdk/types" "^0.1.0-preview.7" + tslib "^1.8.0" + +"@aws-sdk/types@^0.1.0-preview.7": + version "0.1.0-preview.7" + resolved "https://registry.yarnpkg.com/@aws-sdk/types/-/types-0.1.0-preview.7.tgz#2c3e8b911c9236e8f48d8ffb3c9df449a067df58" + integrity sha512-gpyU8N9XEs8diE4uW9B6/hjKDrB/c4a1GF4ICwkaGYpXrbJy9QLrEU8Hk4rC6P1l++YYyJKMl7RjMmTyBtNOzw== + "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d" @@ -1549,6 +1579,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.16.tgz#4d690c96cbb7b2728afea0e260d680501b3da5cf" integrity sha512-/opXIbfn0P+VLt+N8DE4l8Mn8rbhiJgabU96ZJ0p9mxOkIks5gh6RUnpHak7Yh0SFkyjO/ODbxsQQPV2bpMmyA== +"@types/node@^12.7.5": + version "12.12.17" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.17.tgz#191b71e7f4c325ee0fb23bc4a996477d92b8c39b" + integrity sha512-Is+l3mcHvs47sKy+afn2O1rV4ldZFU7W8101cNlOd+MRbjM4Onida8jSZnJdTe/0Pcf25g9BNIUsuugmE6puHA== + "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" @@ -2084,6 +2119,13 @@ babel-runtime@^6.23.0, babel-runtime@^6.26.0: core-js "^2.4.0" regenerator-runtime "^0.11.0" +backbone@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/backbone/-/backbone-1.4.0.tgz#54db4de9df7c3811c3f032f34749a4cd27f3bd12" + integrity sha512-RLmDrRXkVdouTg38jcgHhyQ/2zjg7a8E6sz2zxfz21Hh17xDJYUHBZimVIt5fUyS8vbfpeSmTL3gUjTEvUV3qQ== + dependencies: + underscore ">=1.8.3" + backo2@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" @@ -4478,6 +4520,17 @@ handlebars@*, handlebars@^4.0.1, handlebars@^4.0.6, handlebars@^4.1.2: optionalDependencies: uglify-js "^3.1.4" +handlebars@^4.5.3: + version "4.5.3" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.5.3.tgz#5cf75bd8714f7605713511a56be7c349becb0482" + integrity sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA== + dependencies: + neo-async "^2.6.0" + optimist "^0.6.1" + source-map "^0.6.1" + optionalDependencies: + uglify-js "^3.1.4" + har-schema@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" @@ -4594,6 +4647,13 @@ highlight.js@^9.13.1: resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.15.10.tgz#7b18ed75c90348c045eef9ed08ca1319a2219ad2" integrity sha512-RoV7OkQm0T3os3Dd2VHLNMoaoDVx77Wygln3n9l5YV172XonWG6rgQD3XnF/BuFFZw9A0TJgmMSO8FEWQgvcXw== +highlight.js@^9.16.2: + version "9.17.1" + resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.17.1.tgz#14a4eded23fd314b05886758bb906e39dd627f9a" + integrity sha512-TA2/doAur5Ol8+iM3Ov7qy3jYcr/QiJ2eDTdRF4dfbjG7AaaB99J5G+zSl11ljbl6cIcahgPY6SKb3sC3EJ0fw== + dependencies: + handlebars "^4.5.3" + hmac-drbg@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -5692,6 +5752,11 @@ jmespath@^0.15.0: resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.15.0.tgz#a3f222a9aae9f966f5d27c796510e28091764217" integrity sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc= +jquery@^3.4.1: + version "3.4.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2" + integrity sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -6274,6 +6339,11 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" +lunr@^2.3.8: + version "2.3.8" + resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.8.tgz#a8b89c31f30b5a044b97d2d28e2da191b6ba2072" + integrity sha512-oxMeX/Y35PNFuZoHp+jUj5OSEmLCaIH4KTFJh7a93cHBoFmpw2IoPs22VIz7vyO2YUnx2Tn9dzIwO2P/4quIRg== + macos-release@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.3.0.tgz#eb1930b036c0800adebccd5f17bc4c12de8bb71f" @@ -6345,6 +6415,11 @@ marked@^0.4.0: resolved "https://registry.yarnpkg.com/marked/-/marked-0.4.0.tgz#9ad2c2a7a1791f10a852e0112f77b571dce10c66" integrity sha512-tMsdNBgOsrUophCAFQl0XPe6Zqk/uy9gnue+jIIKhykO51hxyu6uNx7zBPy0+y/WKYVZZMspV9YeXLNdKk+iYw== +marked@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/marked/-/marked-0.7.0.tgz#b64201f051d271b1edc10a04d1ae9b74bb8e5c0e" + integrity sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg== + md5.js@^1.3.4: version "1.3.5" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" @@ -7553,7 +7628,7 @@ process@^0.7.0: resolved "https://registry.yarnpkg.com/process/-/process-0.7.0.tgz#c52208161a34adf3812344ae85d3e6150469389d" integrity sha1-xSIIFho0rfOBI0SuhdPmFQRpOJ0= -progress@^2.0.0, progress@^2.0.1: +progress@^2.0.0, progress@^2.0.1, progress@^2.0.3: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8" integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== @@ -8196,6 +8271,13 @@ rimraf@2, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.0, rimraf@^2.6.1, rimraf@^2. dependencies: glob "^7.1.3" +rimraf@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.0.tgz#614176d4b3010b75e5c390eb0ee96f6dc0cebb9b" + integrity sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg== + dependencies: + glob "^7.1.3" + ripemd160@^2.0.0, ripemd160@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" @@ -8378,7 +8460,7 @@ shell-quote@~0.0.1: resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-0.0.1.tgz#1a41196f3c0333c482323593d6886ecf153dd986" integrity sha1-GkEZbzwDM8SCMjWT1ohuzxU92YY= -shelljs@^0.8.2: +shelljs@^0.8.2, shelljs@^0.8.3: version "0.8.3" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097" integrity sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A== @@ -9298,6 +9380,16 @@ typedoc-default-themes@^0.5.0: resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.5.0.tgz#6dc2433e78ed8bea8e887a3acde2f31785bd6227" integrity sha1-bcJDPnjti+qOiHo6zeLzF4W9Yic= +typedoc-default-themes@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/typedoc-default-themes/-/typedoc-default-themes-0.6.1.tgz#e2e471188983df995f4f9df49f713044fced6802" + integrity sha512-z5AWKqQDz7igl9WkUuafx8cEm4MPVQGMpbWE+3lwVOaq+U4UoLKBMnpFQWh/4fqQ3bGysXpOstMxy2OOzHezyw== + dependencies: + backbone "^1.4.0" + jquery "^3.4.1" + lunr "^2.3.8" + underscore "^1.9.1" + typedoc@^0.14.2: version "0.14.2" resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.14.2.tgz#769f457f4f9e4bdb8b5f3b177c86b6a31d8c3dc3" @@ -9321,11 +9413,33 @@ typedoc@^0.14.2: typedoc-default-themes "^0.5.0" typescript "3.2.x" +typedoc@^0.15.0: + version "0.15.4" + resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.15.4.tgz#23f2c1e2be41af879c0f1358aeb76cd4d39d9aeb" + integrity sha512-XzrV8sM44j4nXGSKt99VOkFCPGLUH9DHGGvcgZJbvqdSG7/iR3HztNjpsLyTu1nybZLLjcClLRuWJDO3icXzYA== + dependencies: + "@types/minimatch" "3.0.3" + fs-extra "^8.1.0" + handlebars "^4.5.3" + highlight.js "^9.16.2" + lodash "^4.17.15" + marked "^0.7.0" + minimatch "^3.0.0" + progress "^2.0.3" + shelljs "^0.8.3" + typedoc-default-themes "^0.6.1" + typescript "3.7.x" + typescript@3.2.x: version "3.2.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d" integrity sha512-0RNDbSdEokBeEAkgNbxJ+BLwSManFy9TeXz8uW+48j/xhEXv1ePME60olyzw2XzUqUBNAYFeJadIqAgNqIACwg== +typescript@3.7.x, typescript@^3.6.3: + version "3.7.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz#b36840668a16458a7025b9eabfad11b66ab85c69" + integrity sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw== + typescript@^3.7.0, typescript@^3.7.0-dev.20190926: version "3.7.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb" @@ -9407,6 +9521,11 @@ underscore@1.8.3: resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022" integrity sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI= +underscore@>=1.8.3, underscore@^1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961" + integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg== + union-value@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847" From 5ee70f4e9d94b8df94b417a85d57ef720c0769b1 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 16 Dec 2019 13:50:27 -0800 Subject: [PATCH 2/4] fix: move static files generation to codegen --- codegen/sdk-codegen/build.gradle.kts | 5 + ...wsPackageFixturesGeneratorIntegration.java | 60 +++++++++++ ....codegen.integration.TypeScriptIntegration | 1 + .../aws/typescript/codegen/LICENCE.template | 2 +- .../aws/typescript/codegen/README.md.template | 6 ++ .../smithy/aws/typescript/codegen/gitignore | 0 .../smithy/aws/typescript/codegen/npmignore | 0 .../typescript/codegen/package.json.template | 7 ++ package.json | 1 - scripts/generate-clients/copy-to-clients.js | 101 +++++------------- .../templates/README.md.sample | 6 -- .../templates/package.json.sample | 41 ------- .../templates/tsconfig.es.json.sample | 18 ---- .../templates/tsconfig.json.sample | 28 ----- 14 files changed, 106 insertions(+), 170 deletions(-) create mode 100644 codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java rename scripts/generate-clients/templates/LICENSE.sample => codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENCE.template (99%) create mode 100644 codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/README.md.template rename scripts/generate-clients/templates/.gitignore.sample => codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/gitignore (100%) rename scripts/generate-clients/templates/.npmignore.sample => codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/npmignore (100%) create mode 100644 codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/package.json.template delete mode 100644 scripts/generate-clients/templates/README.md.sample delete mode 100644 scripts/generate-clients/templates/package.json.sample delete mode 100644 scripts/generate-clients/templates/tsconfig.es.json.sample delete mode 100644 scripts/generate-clients/templates/tsconfig.json.sample diff --git a/codegen/sdk-codegen/build.gradle.kts b/codegen/sdk-codegen/build.gradle.kts index 2ebec32e4d03..769687c3b35e 100644 --- a/codegen/sdk-codegen/build.gradle.kts +++ b/codegen/sdk-codegen/build.gradle.kts @@ -44,6 +44,10 @@ tasks.register("generate-smithy-build") { fileTree("aws-models").filter { it.isFile }.files.forEach { file -> val (sdkId, version, remaining) = file.name.split(".") + var manifestOverwrites = Node.parse( + File("smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/package.json.template") + .readText() + ).expectObjectNode() val projectionContents = Node.objectNodeBuilder() .withMember("imports", Node.fromStrings("aws-models/" + file.name)) .withMember("plugins", Node.objectNode() @@ -51,6 +55,7 @@ tasks.register("generate-smithy-build") { .withMember("package", "@aws-sdk/client-" + sdkId.toLowerCase()) // Note that this version is replaced by Lerna when publishing. .withMember("packageVersion", "1.0.0") + .withMember("packageJson", manifestOverwrites) .build())) .build() projectionsBuilder.withMember(sdkId + "." + version.toLowerCase(), projectionContents) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java new file mode 100644 index 000000000000..eec2c927c609 --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java @@ -0,0 +1,60 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package software.amazon.smithy.aws.typescript.codegen; + +import java.util.Calendar; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.typescript.codegen.TypeScriptSettings; +import software.amazon.smithy.typescript.codegen.TypeScriptWriter; +import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; +import software.amazon.smithy.utils.IoUtils; + + +public class AwsPackageFixturesGeneratorIntegration implements TypeScriptIntegration { + @Override + public void writeAdditionalFiles( + TypeScriptSettings settings, + Model model, + SymbolProvider symbolProvider, + BiConsumer> writerFactory + ) { + writerFactory.accept(".gitignore", writer -> { + String resource = IoUtils.readUtf8Resource( + getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/gitignore"); + writer.write(resource); + }); + writerFactory.accept(".npmignore", writer -> { + String resource = IoUtils.readUtf8Resource( + getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/npmignore"); + writer.write(resource); + }); + writerFactory.accept("LICENCE", writer -> { + String resource = IoUtils.readUtf8Resource( + getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/LICENCE.template"); + resource = resource.replace("${year}", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))); + writer.write(resource); + }); + writerFactory.accept("README.md", writer -> { + String resource = IoUtils.readUtf8Resource( + getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/README.md.template"); + resource = resource.replaceAll("\\$\\{packageName\\}", settings.getPackageName()); + writer.write(resource); + }); + } +} diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration b/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration index ded8dff53a5c..dd4caaffddd8 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration @@ -2,5 +2,6 @@ software.amazon.smithy.aws.typescript.codegen.AddAwsRuntimeConfig software.amazon.smithy.aws.typescript.codegen.AddBuiltinPlugins software.amazon.smithy.aws.typescript.codegen.AddProtocols software.amazon.smithy.aws.typescript.codegen.AwsServiceIdIntegration +software.amazon.smithy.aws.typescript.codegen.AwsPackageFixturesGeneratorIntegration software.amazon.smithy.aws.typescript.codegen.AddMd5HashDependency software.amazon.smithy.aws.typescript.codegen.AddStreamHasherDependency diff --git a/scripts/generate-clients/templates/LICENSE.sample b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENCE.template similarity index 99% rename from scripts/generate-clients/templates/LICENSE.sample rename to codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENCE.template index e7bd4e8b4d20..a70ad0637b84 100644 --- a/scripts/generate-clients/templates/LICENSE.sample +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENCE.template @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {{year}} Amazon.com, Inc. or its affiliates. All Rights Reserved. + Copyright ${year} Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/README.md.template b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/README.md.template new file mode 100644 index 000000000000..0071f46c25ff --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/README.md.template @@ -0,0 +1,6 @@ +${packageName} + +[![NPM version](https://img.shields.io/npm/v/${packageName}/preview.svg)](https://www.npmjs.com/package/${packageName}) +[![NPM downloads](https://img.shields.io/npm/dm/${packageName}.svg)](https://www.npmjs.com/package/${packageName}) + +For SDK usage, please step to [SDK reademe](https://github.com/aws/aws-sdk-js-v3). diff --git a/scripts/generate-clients/templates/.gitignore.sample b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/gitignore similarity index 100% rename from scripts/generate-clients/templates/.gitignore.sample rename to codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/gitignore diff --git a/scripts/generate-clients/templates/.npmignore.sample b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/npmignore similarity index 100% rename from scripts/generate-clients/templates/.npmignore.sample rename to codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/npmignore diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/package.json.template b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/package.json.template new file mode 100644 index 000000000000..cb857a66e0c4 --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/package.json.template @@ -0,0 +1,7 @@ +{ + "author": { + "name": "AWS SDK for JavaScript Team", + "url": "https://aws.amazon.com/javascript/" + }, + "license": "Apache-2.0" +} \ No newline at end of file diff --git a/package.json b/package.json index ae48fdc9a859..cac7e517d554 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "cucumber": "0.5.x", "fs-extra": "^8.1.0", "generate-changelog": "^1.7.1", - "handlebars": "^4.5.3", "husky": "^3.0.0", "jest": "^24.7.1", "jmespath": "^0.15.0", diff --git a/scripts/generate-clients/copy-to-clients.js b/scripts/generate-clients/copy-to-clients.js index 638cfa7e8311..5e7b52452f42 100644 --- a/scripts/generate-clients/copy-to-clients.js +++ b/scripts/generate-clients/copy-to-clients.js @@ -1,13 +1,6 @@ const { join, normalize } = require("path"); const { copySync, ensureDirSync } = require("fs-extra"); -const handlebars = require("handlebars"); -const { - readdirSync, - lstatSync, - readFileSync, - existsSync, - writeFileSync -} = require("fs"); +const { readdirSync, lstatSync, readFileSync, existsSync } = require("fs"); const CODE_GEN_OUTPUT_DIR = normalize( join( @@ -22,18 +15,27 @@ const CODE_GEN_OUTPUT_DIR = normalize( ) ); -/** - * templates are a black list of files we don't want codegen artifact - * to override in the clients folder - */ -const templates = readdirSync(join(__dirname, "templates")) - .filter(name => /.sample$/.test(name)) - .reduce((accumulator, curr) => { - const templatePath = join(__dirname, "templates", curr); - const template = readFileSync(templatePath).toString(); - accumulator[curr.replace(/.sample$/, "")] = template; - return accumulator; - }, {}); +const getOverwritablePredicate = packageName => pathName => { + const overwritablePathnames = [ + "commands", + "lib", + "models", + "protocols", + "LICENCE", + "runtimeConfig.ts", + "runtimeConfig.browser.ts", + "runtimeConfig.shared.ts", + "index.ts" + ]; + return ( + pathName.toLowerCase().indexOf( + packageName + .toLowerCase() + .replace("@aws-sdk/client-", "") + .replace("-", "") + ) >= 0 || overwritablePathnames.indexOf(pathName) >= 0 + ); +}; async function copyToClients(clientsDir) { for (const modelName of readdirSync(CODE_GEN_OUTPUT_DIR)) { @@ -55,44 +57,12 @@ async function copyToClients(clientsDir) { const packageName = packageManifest.name; console.log(`copying ${packageName} from ${artifactPath} to ${clientsDir}`); const destPath = join(clientsDir, packageName.replace("@aws-sdk/", "")); - - //Data used to generate files from template - const templateData = { - year: new Date().getFullYear(), - packageName - }; - - for (const packageSub of [ - ...readdirSync(artifactPath), - ...Object.keys(templates) - ]) { + const overwritablePredicate = getOverwritablePredicate(packageName); + for (const packageSub of readdirSync(artifactPath)) { const packageSubPath = join(artifactPath, packageSub); const destSubPath = join(destPath, packageSub); - - if (Object.keys(templates).indexOf(packageSub) >= 0) { - if (packageSub === "package.json") { - /** - * Copy package.json content in detail. - * Basically merge the generated package.json and dest package.json - * but prefer the values from dest when they contain the same key - * */ - const destManifest = JSON.parse( - existsSync(destSubPath) - ? readFileSync(destSubPath).toString() - : handlebars.compile(templates[packageSub])(templateData) - ); - const updatedManifest = mergeManifest(packageManifest, destManifest); - writeFileSync(destSubPath, JSON.stringify(updatedManifest, null, 2)); - } else if (!existsSync(destSubPath)) { - //for files not yet exists and we have a template for it; generate from template - const file = handlebars.compile(templates[packageSub])(templateData); - writeFileSync(destSubPath, file); - } else { - //for files we have template but we already have a new version in clients folder, always prefer current one - //PASS - } - } else { - //For things not in codegen artifact black list, overwrite the existing ones. + if (overwritablePredicate(packageSub) || !existsSync(destSubPath)) { + //Overwrite the directories and files that are overwritable, or not yet exists if (lstatSync(packageSubPath).isDirectory()) ensureDirSync(destSubPath); copySync(packageSubPath, destSubPath, { overwrite: true }); } @@ -100,23 +70,4 @@ async function copyToClients(clientsDir) { } } -const mergeManifest = (source, dest) => { - return { - ...source, - ...dest, - scripts: { - ...source.scripts, - ...dest.scripts - }, - dependencies: { - ...source.dependencies, - ...dest.dependencies - }, - devDependencies: { - ...source.devDependencies, - ...dest.devDependencies - } - }; -}; - module.exports = { copyToClients, CODE_GEN_OUTPUT_DIR }; diff --git a/scripts/generate-clients/templates/README.md.sample b/scripts/generate-clients/templates/README.md.sample deleted file mode 100644 index 81fe125ea655..000000000000 --- a/scripts/generate-clients/templates/README.md.sample +++ /dev/null @@ -1,6 +0,0 @@ -{{packageName}} - -[![NPM version](https://img.shields.io/npm/v/{{packageName}}/preview.svg)](https://www.npmjs.com/package/{{packageName}}) -[![NPM downloads](https://img.shields.io/npm/dm/{{packageName}}.svg)](https://www.npmjs.com/package/{{packageName}}) - -For SDK usage, please step to [SDK reademe](https://github.com/aws/aws-sdk-js-v3). diff --git a/scripts/generate-clients/templates/package.json.sample b/scripts/generate-clients/templates/package.json.sample deleted file mode 100644 index 15d138d6a0ba..000000000000 --- a/scripts/generate-clients/templates/package.json.sample +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "0.1.0-preview.3", - "scripts": { - "clean": "npm run remove-definitions && npm run remove-dist && npm run remove-js && npm run remove-maps", - "build-documentation": "npm run clean && typedoc ./", - "prepublishOnly": "yarn build", - "pretest": "tsc", - "remove-definitions": "rimraf ./types", - "remove-dist": "rimraf ./dist", - "remove-documentation": "rimraf ./docs", - "remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./lib/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js", - "remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./lib/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map", - "build:es": "tsc -p tsconfig.es.json", - "build": "yarn pretest && yarn build:es" - }, - "main": "./dist/cjs/index.js", - "types": "./types/index.d.ts", - "author": { - "name": "AWS SDK for JavaScript Team", - "url": "https://aws.amazon.com/javascript/" - }, - "module": "./dist/es/index.js", - "browser": { - "./runtimeConfig": "./runtimeConfig.browser" - }, - "sideEffects": false, - "license": "Apache-2.0", - "dependencies": { - "tslib": "^1.8.0" - }, - "devDependencies": { - "@aws-sdk/client-documentation-generator": "^0.1.0-preview.3", - "@types/node": "^10.0.0", - "rimraf": "^3.0.0", - "typedoc": "^0.15.0", - "typescript": "^3.7.0" - }, - "engines": { - "node": ">=8.0.0" - } -} diff --git a/scripts/generate-clients/templates/tsconfig.es.json.sample b/scripts/generate-clients/templates/tsconfig.es.json.sample deleted file mode 100644 index 60e5ef3e90cd..000000000000 --- a/scripts/generate-clients/templates/tsconfig.es.json.sample +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "target": "es5", - "module": "esnext", - "moduleResolution": "node", - "declaration": false, - "declarationDir": null, - "lib": [ - "es5", - "es2015.promise", - "es2015.collection", - "es2015.iterable", - "es2015.symbol.wellknown" - ], - "outDir": "dist/es" - } -} diff --git a/scripts/generate-clients/templates/tsconfig.json.sample b/scripts/generate-clients/templates/tsconfig.json.sample deleted file mode 100644 index 181286d5daef..000000000000 --- a/scripts/generate-clients/templates/tsconfig.json.sample +++ /dev/null @@ -1,28 +0,0 @@ -{ - "compilerOptions": { - "alwaysStrict": true, - "target": "es2017", - "module": "commonjs", - "declaration": true, - "strict": true, - "sourceMap": true, - "downlevelIteration": true, - "importHelpers": true, - "noEmitHelpers": true, - "incremental": true, - "resolveJsonModule": true, - "noUnusedLocals": true, - "declarationDir": "./types", - "outDir": "dist/cjs" - }, - "typedocOptions": { - "exclude": "**/node_modules/**", - "excludedNotExported": true, - "excludePrivate": true, - "hideGenerator": true, - "ignoreCompilerErrors": true, - "mode": "file", - "out": "./docs", - "plugin": "@aws-sdk/client-documentation-generator" - } -} \ No newline at end of file From f1b371d01e1b96f683baf0ee57e6611fbb3e199e Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Mon, 16 Dec 2019 17:07:24 -0800 Subject: [PATCH 3/4] fix: get rid of full pathname when loading fixtures templates --- .../AwsPackageFixturesGeneratorIntegration.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java index eec2c927c609..8693abacf5e9 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java @@ -25,7 +25,6 @@ import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; import software.amazon.smithy.utils.IoUtils; - public class AwsPackageFixturesGeneratorIntegration implements TypeScriptIntegration { @Override public void writeAdditionalFiles( @@ -35,24 +34,20 @@ public void writeAdditionalFiles( BiConsumer> writerFactory ) { writerFactory.accept(".gitignore", writer -> { - String resource = IoUtils.readUtf8Resource( - getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/gitignore"); + String resource = IoUtils.readUtf8Resource(getClass(), "gitignore"); writer.write(resource); }); writerFactory.accept(".npmignore", writer -> { - String resource = IoUtils.readUtf8Resource( - getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/npmignore"); + String resource = IoUtils.readUtf8Resource(getClass(), "npmignore"); writer.write(resource); }); writerFactory.accept("LICENCE", writer -> { - String resource = IoUtils.readUtf8Resource( - getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/LICENCE.template"); + String resource = IoUtils.readUtf8Resource(getClass(), "LICENCE.template"); resource = resource.replace("${year}", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))); writer.write(resource); }); writerFactory.accept("README.md", writer -> { - String resource = IoUtils.readUtf8Resource( - getClass().getClassLoader(), "software/amazon/smithy/aws/typescript/codegen/README.md.template"); + String resource = IoUtils.readUtf8Resource(getClass(), "README.md.template"); resource = resource.replaceAll("\\$\\{packageName\\}", settings.getPackageName()); writer.write(resource); }); From 0417fa9d84fbd3316f914d2eed08aea76c18dcdb Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Tue, 17 Dec 2019 13:53:30 -0800 Subject: [PATCH 4/4] chore: add test for package fixtures generator --- ...wsPackageFixturesGeneratorIntegration.java | 10 +++-- .../{LICENCE.template => LICENSE.template} | 0 ...ckageFixturesGeneratorIntegrationTest.java | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) rename codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/{LICENCE.template => LICENSE.template} (100%) create mode 100644 codegen/smithy-aws-typescript-codegen/src/test/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegrationTest.java diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java index 8693abacf5e9..4dab62986d24 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegration.java @@ -18,6 +18,8 @@ import java.util.Calendar; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.regex.Pattern; + import software.amazon.smithy.codegen.core.SymbolProvider; import software.amazon.smithy.model.Model; import software.amazon.smithy.typescript.codegen.TypeScriptSettings; @@ -25,7 +27,7 @@ import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; import software.amazon.smithy.utils.IoUtils; -public class AwsPackageFixturesGeneratorIntegration implements TypeScriptIntegration { +public final class AwsPackageFixturesGeneratorIntegration implements TypeScriptIntegration { @Override public void writeAdditionalFiles( TypeScriptSettings settings, @@ -41,14 +43,14 @@ public void writeAdditionalFiles( String resource = IoUtils.readUtf8Resource(getClass(), "npmignore"); writer.write(resource); }); - writerFactory.accept("LICENCE", writer -> { - String resource = IoUtils.readUtf8Resource(getClass(), "LICENCE.template"); + writerFactory.accept("LICENSE", writer -> { + String resource = IoUtils.readUtf8Resource(getClass(), "LICENSE.template"); resource = resource.replace("${year}", Integer.toString(Calendar.getInstance().get(Calendar.YEAR))); writer.write(resource); }); writerFactory.accept("README.md", writer -> { String resource = IoUtils.readUtf8Resource(getClass(), "README.md.template"); - resource = resource.replaceAll("\\$\\{packageName\\}", settings.getPackageName()); + resource = resource.replaceAll(Pattern.quote("${packageName}"), settings.getPackageName()); writer.write(resource); }); } diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENCE.template b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENSE.template similarity index 100% rename from codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENCE.template rename to codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/LICENSE.template diff --git a/codegen/smithy-aws-typescript-codegen/src/test/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegrationTest.java b/codegen/smithy-aws-typescript-codegen/src/test/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegrationTest.java new file mode 100644 index 000000000000..3993071c8ef6 --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/test/java/software/amazon/smithy/aws/typescript/codegen/AwsPackageFixturesGeneratorIntegrationTest.java @@ -0,0 +1,37 @@ +package software.amazon.smithy.aws.typescript.codegen; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import software.amazon.smithy.build.MockManifest; +import software.amazon.smithy.build.PluginContext; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.node.Node; +import software.amazon.smithy.typescript.codegen.TypeScriptCodegenPlugin; + +public class AwsPackageFixturesGeneratorIntegrationTest { + @Test + public void expandsPackageFixtureFiles() { + Model model = Model.assembler() + .addImport(getClass().getResource("serviceid.smithy")) + .discoverModels() + .assemble() + .unwrap(); + MockManifest manifest = new MockManifest(); + PluginContext context = PluginContext.builder() + .model(model) + .fileManifest(manifest) + .settings(Node.objectNodeBuilder() + .withMember("service", Node.from("smithy.example#OriginalName")) + .withMember("package", Node.from("example")) + .withMember("packageVersion", Node.from("1.0.0")) + .build()) + .build(); + + new TypeScriptCodegenPlugin().execute(context); + + Assertions.assertTrue(manifest.hasFile("LICENSE")); + Assertions.assertTrue(manifest.hasFile(".gitignore")); + Assertions.assertTrue(manifest.hasFile(".npmignore")); + Assertions.assertTrue(manifest.hasFile("README.md")); + } +}