From b11fd42d249a1c861c8a3c593945504966a0ff82 Mon Sep 17 00:00:00 2001 From: Paul Li Date: Mon, 13 May 2019 22:33:56 +1000 Subject: [PATCH 1/2] feat(cli): Add javascript for init-templates/sample-app --- packages/aws-cdk/.gitignore | 2 +- .../sample-app/javascript/.template.gitignore | 4 ++++ .../sample-app/javascript/.template.npmignore | 2 ++ .../sample-app/javascript/README.md | 7 ++++++ .../javascript/bin/%name%.template.js | 6 +++++ .../sample-app/javascript/cdk.template.json | 3 +++ .../javascript/lib/%name%-stack.template.js | 24 +++++++++++++++++++ .../javascript/package.template.json | 22 +++++++++++++++++ .../sample-app/javascript/tsconfig.json | 24 +++++++++++++++++++ 9 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.gitignore create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.npmignore create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/bin/%name%.template.js create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/cdk.template.json create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/lib/%name%-stack.template.js create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/package.template.json create mode 100644 packages/aws-cdk/lib/init-templates/sample-app/javascript/tsconfig.json diff --git a/packages/aws-cdk/.gitignore b/packages/aws-cdk/.gitignore index 1d6901e68114e..00f5e67ea2b57 100644 --- a/packages/aws-cdk/.gitignore +++ b/packages/aws-cdk/.gitignore @@ -1,7 +1,7 @@ *.js *.js.map *.d.ts -!lib/init-templates/app/javascript/**/* +!lib/init-templates/**/javascript/**/* node_modules dist diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.gitignore b/packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.gitignore new file mode 100644 index 0000000000000..80cabb688731b --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.gitignore @@ -0,0 +1,4 @@ +node_modules + +# CDK asset staging directory +.cdk.staging diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.npmignore b/packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.npmignore new file mode 100644 index 0000000000000..d4928914d3e88 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/.template.npmignore @@ -0,0 +1,2 @@ +# CDK asset staging directory +.cdk.staging diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md b/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md new file mode 100644 index 0000000000000..5950bf1c8d08b --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md @@ -0,0 +1,7 @@ +# Useful commands + + * `npm run test` check javascript error + * `npm run test:watch` watch for changes and check javascript error + * `cdk deploy` deploy this stack to your default AWS account/region + * `cdk diff` compare deployed stack with current state + * `cdk synth` emits the synthesized CloudFormation template diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/bin/%name%.template.js b/packages/aws-cdk/lib/init-templates/sample-app/javascript/bin/%name%.template.js new file mode 100644 index 0000000000000..acdd6c5c26029 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/bin/%name%.template.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node +const cdk = require('@aws-cdk/cdk'); +const { %name.PascalCased%Stack } = require('../lib/%name%-stack'); + +const app = new cdk.App(); +new %name.PascalCased%Stack(app, '%name.PascalCased%Stack'); diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/cdk.template.json b/packages/aws-cdk/lib/init-templates/sample-app/javascript/cdk.template.json new file mode 100644 index 0000000000000..ca1d40ed37e2d --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/cdk.template.json @@ -0,0 +1,3 @@ +{ + "app": "node bin/%name%.js" +} diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/lib/%name%-stack.template.js b/packages/aws-cdk/lib/init-templates/sample-app/javascript/lib/%name%-stack.template.js new file mode 100644 index 0000000000000..b44839ec48f78 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/lib/%name%-stack.template.js @@ -0,0 +1,24 @@ +const sns = require('@aws-cdk/aws-sns'); +const sqs = require('@aws-cdk/aws-sqs'); +const cdk = require('@aws-cdk/cdk'); + +class %name.PascalCased%Stack extends cdk.Stack { + /** + * @param {cdk.App} scope + * @param {string} id + * @param {cdk.StackProps=} props + */ + constructor(scope, id, props) { + super(scope, id, props); + + const queue = new sqs.Queue(this, '%name.PascalCased%Queue', { + visibilityTimeoutSec: 300 + }); + + const topic = new sns.Topic(this, '%name.PascalCased%Topic'); + + topic.subscribeQueue(queue); + } +} + +module.exports = { %name.PascalCased%Stack } diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/package.template.json b/packages/aws-cdk/lib/init-templates/sample-app/javascript/package.template.json new file mode 100644 index 0000000000000..f32dfb80207b6 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/package.template.json @@ -0,0 +1,22 @@ +{ + "name": "%name%", + "version": "0.1.0", + "bin": { + "%name%": "bin/%name%.js" + }, + "scripts": { + "test": "tsc", + "test:watch": "tsc -w", + "cdk": "cdk" + }, + "devDependencies": { + "@types/node": "8.10.45", + "typescript": "^3.3.3333", + "aws-cdk": "^%cdk-version%" + }, + "dependencies": { + "@aws-cdk/aws-sns": "^%cdk-version%", + "@aws-cdk/aws-sqs": "^%cdk-version%", + "@aws-cdk/cdk": "^%cdk-version%" + } +} diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/tsconfig.json b/packages/aws-cdk/lib/init-templates/sample-app/javascript/tsconfig.json new file mode 100644 index 0000000000000..394d006e36fa0 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target":"ES2018", + "module": "commonjs", + "lib": ["es2016", "es2017.object", "es2017.string"], + "declaration": true, + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "noImplicitThis": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": false, + "inlineSourceMap": true, + "inlineSources": true, + "experimentalDecorators": true, + "strictPropertyInitialization":false, + "allowJs": true, + "checkJs": true, + "noEmit": true + } +} From f53884185a80c68a09cda086505beaca78371d3e Mon Sep 17 00:00:00 2001 From: Paul Li Date: Tue, 14 May 2019 09:42:58 +1000 Subject: [PATCH 2/2] chore: updated readme --- packages/aws-cdk/lib/init-templates/app/javascript/README.md | 4 ++-- .../lib/init-templates/sample-app/javascript/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/README.md b/packages/aws-cdk/lib/init-templates/app/javascript/README.md index 5950bf1c8d08b..100817e8db412 100644 --- a/packages/aws-cdk/lib/init-templates/app/javascript/README.md +++ b/packages/aws-cdk/lib/init-templates/app/javascript/README.md @@ -1,7 +1,7 @@ # Useful commands - * `npm run test` check javascript error - * `npm run test:watch` watch for changes and check javascript error + * `npm run test` check javascript error using the typescript compiler + * `npm run test:watch` watch for changes and check javascript error using the typescript compiler * `cdk deploy` deploy this stack to your default AWS account/region * `cdk diff` compare deployed stack with current state * `cdk synth` emits the synthesized CloudFormation template diff --git a/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md b/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md index 5950bf1c8d08b..100817e8db412 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md +++ b/packages/aws-cdk/lib/init-templates/sample-app/javascript/README.md @@ -1,7 +1,7 @@ # Useful commands - * `npm run test` check javascript error - * `npm run test:watch` watch for changes and check javascript error + * `npm run test` check javascript error using the typescript compiler + * `npm run test:watch` watch for changes and check javascript error using the typescript compiler * `cdk deploy` deploy this stack to your default AWS account/region * `cdk diff` compare deployed stack with current state * `cdk synth` emits the synthesized CloudFormation template