From 57700a7c7ca4447b5962d77d73f6a5d096c8edfc Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 19 Nov 2018 16:37:25 +0100 Subject: [PATCH] chore: move stack from 'bin' to a file in 'lib' Generally we recommend people write reusable constructs in 'lib' directories, and they should put stacks there as well. Change the init template to reflect this change. Fixes #1128. --- .../app/typescript/bin/%name%.template.ts | 19 +-------- .../app/typescript/cdk.template.json | 2 +- .../typescript/lib/%name%-stack.template.ts | 17 ++++++++ .../app/typescript/package.template.json | 42 +++++++++---------- .../app/typescript/tsconfig.json | 39 +++++++++-------- 5 files changed, 58 insertions(+), 61 deletions(-) create mode 100644 packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/bin/%name%.template.ts b/packages/aws-cdk/lib/init-templates/app/typescript/bin/%name%.template.ts index 9034084dba024..985ea7add8f96 100644 --- a/packages/aws-cdk/lib/init-templates/app/typescript/bin/%name%.template.ts +++ b/packages/aws-cdk/lib/init-templates/app/typescript/bin/%name%.template.ts @@ -1,24 +1,7 @@ #!/usr/bin/env node -import sns = require('@aws-cdk/aws-sns'); -import sqs = require('@aws-cdk/aws-sqs'); import cdk = require('@aws-cdk/cdk'); - -class %name.PascalCased%Stack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); - - const queue = new sqs.Queue(this, '%name.PascalCased%Queue', { - visibilityTimeoutSec: 300 - }); - - const topic = new sns.Topic(this, '%name.PascalCased%Topic'); - - topic.subscribeQueue(queue); - } -} +import { %name.PascalCased%Stack } from '../lib/%name%-stack'; const app = new cdk.App(); - new %name.PascalCased%Stack(app, '%name.PascalCased%Stack'); - app.run(); diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/cdk.template.json b/packages/aws-cdk/lib/init-templates/app/typescript/cdk.template.json index 9fe544e21a177..ca1d40ed37e2d 100644 --- a/packages/aws-cdk/lib/init-templates/app/typescript/cdk.template.json +++ b/packages/aws-cdk/lib/init-templates/app/typescript/cdk.template.json @@ -1,3 +1,3 @@ { - "app": "node bin/%name%.js" + "app": "node bin/%name%.js" } diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts b/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts new file mode 100644 index 0000000000000..9703102063490 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts @@ -0,0 +1,17 @@ +import sns = require('@aws-cdk/aws-sns'); +import sqs = require('@aws-cdk/aws-sqs'); +import cdk = require('@aws-cdk/cdk'); + +export class %name.PascalCased%Stack extends cdk.Stack { + constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { + super(parent, name, props); + + const queue = new sqs.Queue(this, '%name.PascalCased%Queue', { + visibilityTimeoutSec: 300 + }); + + const topic = new sns.Topic(this, '%name.PascalCased%Topic'); + + topic.subscribeQueue(queue); + } +} diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json b/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json index ab2d5935b72f9..e84084ccff060 100644 --- a/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json +++ b/packages/aws-cdk/lib/init-templates/app/typescript/package.template.json @@ -1,24 +1,22 @@ { - "name": "%name%", - "version": "0.1.0", - "main": "bin/index.js", - "types": "bin/index.d.ts", - "bin": { - "%name%": "bin/%name%.js" - }, - "scripts": { - "build": "tsc", - "watch": "tsc -w", - "cdk": "cdk" - }, - "devDependencies": { - "@types/node": "^8.9.4", - "typescript": "^3.1.2", - "aws-cdk": "^%cdk-version%" - }, - "dependencies": { - "@aws-cdk/aws-sns": "^%cdk-version%", - "@aws-cdk/aws-sqs": "^%cdk-version%", - "@aws-cdk/cdk": "^%cdk-version%" - } + "name": "%name%", + "version": "0.1.0", + "bin": { + "%name%": "bin/%name%.js" + }, + "scripts": { + "build": "tsc", + "watch": "tsc -w", + "cdk": "cdk" + }, + "devDependencies": { + "@types/node": "^8.9.4", + "typescript": "^3.1.2", + "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/app/typescript/tsconfig.json b/packages/aws-cdk/lib/init-templates/app/typescript/tsconfig.json index 86197fd793270..7520c5f08f852 100644 --- a/packages/aws-cdk/lib/init-templates/app/typescript/tsconfig.json +++ b/packages/aws-cdk/lib/init-templates/app/typescript/tsconfig.json @@ -1,22 +1,21 @@ { - "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 - } + "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 + } } -