diff --git a/packages/aws-cdk/integ-tests/test-init-template.sh b/packages/aws-cdk/integ-tests/test-init-template.sh new file mode 100755 index 0000000000000..a17bad0b3ce29 --- /dev/null +++ b/packages/aws-cdk/integ-tests/test-init-template.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -euo pipefail +scriptdir=$(cd $(dirname $0) && pwd) +source ${scriptdir}/common.bash +# ---------------------------------------------------------- + +rm -rf /tmp/cdk-integ-test +mkdir -p /tmp/cdk-integ-test +cd /tmp/cdk-integ-test + +cdk init app -l typescript +npm run build +cdk synth + +rm -rf /tmp/cdk-integ-test +mkdir -p /tmp/cdk-integ-test +cd /tmp/cdk-integ-test + +cdk init sample-app -l typescript +npm run build +cdk synth + +rm -rf /tmp/cdk-integ-test +mkdir -p /tmp/cdk-integ-test +cd /tmp/cdk-integ-test + +cdk init lib -l typescript +npm run build + +echo "✅ success" + 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..00704b84cd968 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts @@ -0,0 +1,9 @@ +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); + + // The code that defines your stack goes here + } +} 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..a31c23f15a814 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,20 @@ { - "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/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 + } } - diff --git a/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts b/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts index e1eb924b6bdfe..f89e1abfa2343 100644 --- a/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts +++ b/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts @@ -13,7 +13,7 @@ export interface %name.PascalCased%Props { export class %name.PascalCased% extends cdk.Construct { /** @returns the ARN of the SQS queue */ - public readonly queueArn: sqs.QueueArn; + public readonly queueArn: string; constructor(parent: cdk.Construct, name: string, props: %name.PascalCased%Props = {}) { super(parent, name); diff --git a/packages/aws-cdk/lib/init-templates/lib/typescript/package.template.json b/packages/aws-cdk/lib/init-templates/lib/typescript/package.template.json index ca54d9905f023..bea17a1fe3e2e 100644 --- a/packages/aws-cdk/lib/init-templates/lib/typescript/package.template.json +++ b/packages/aws-cdk/lib/init-templates/lib/typescript/package.template.json @@ -1,24 +1,24 @@ { - "name": "%name%", - "version": "0.1.0", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "scripts": { - "prepare": "tsc", - "watch": "tsc -w", - "test": "nodeunit test/test.*.js" - }, - "devDependencies": { - "@types/nodeunit": "^0.0.30", - "nodeunit": "^0.11.2", - "typescript": "^3.1.2" - }, - "peerDependencies": { - "@aws-cdk/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", + "main": "lib/index.js", + "types": "lib/index.d.ts", + "scripts": { + "build": "tsc", + "watch": "tsc -w", + "test": "nodeunit test/test.*.js" + }, + "devDependencies": { + "@types/nodeunit": "^0.0.30", + "nodeunit": "^0.11.2", + "typescript": "^3.1.2" + }, + "peerDependencies": { + "@aws-cdk/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/lib/typescript/tsconfig.json b/packages/aws-cdk/lib/init-templates/lib/typescript/tsconfig.json index 86197fd793270..5aeac13cd6ea6 100644 --- a/packages/aws-cdk/lib/init-templates/lib/typescript/tsconfig.json +++ b/packages/aws-cdk/lib/init-templates/lib/typescript/tsconfig.json @@ -1,22 +1,22 @@ { - "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 + } } diff --git a/packages/aws-cdk/lib/init-templates/sample-app/info.json b/packages/aws-cdk/lib/init-templates/sample-app/info.json new file mode 100644 index 0000000000000..1451c2576eb63 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/info.json @@ -0,0 +1,4 @@ +{ + "description": "Example CDK Application with some constructs", + "aliases": ["sample", "example"] +} diff --git a/packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.gitignore b/packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.gitignore new file mode 100644 index 0000000000000..64d60cacf04a2 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.gitignore @@ -0,0 +1,3 @@ +*.js +*.d.ts +node_modules diff --git a/packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.npmignore b/packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.npmignore new file mode 100644 index 0000000000000..f0e06b3b5ec1d --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.npmignore @@ -0,0 +1,2 @@ +*.ts +!*.d.ts diff --git a/packages/aws-cdk/lib/init-templates/sample-app/typescript/README.md b/packages/aws-cdk/lib/init-templates/sample-app/typescript/README.md new file mode 100644 index 0000000000000..4fd573da16553 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/README.md @@ -0,0 +1,7 @@ +# Useful commands + + * `npm run build` compile typescript to js + * `npm run watch` watch for changes and compile + * `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/typescript/bin/%name%.template.ts b/packages/aws-cdk/lib/init-templates/sample-app/typescript/bin/%name%.template.ts new file mode 100644 index 0000000000000..985ea7add8f96 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/bin/%name%.template.ts @@ -0,0 +1,7 @@ +#!/usr/bin/env node +import cdk = require('@aws-cdk/cdk'); +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/sample-app/typescript/cdk.template.json b/packages/aws-cdk/lib/init-templates/sample-app/typescript/cdk.template.json new file mode 100644 index 0000000000000..ca1d40ed37e2d --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/cdk.template.json @@ -0,0 +1,3 @@ +{ + "app": "node bin/%name%.js" +} diff --git a/packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts b/packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts new file mode 100644 index 0000000000000..9703102063490 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-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/sample-app/typescript/package.template.json b/packages/aws-cdk/lib/init-templates/sample-app/typescript/package.template.json new file mode 100644 index 0000000000000..e84084ccff060 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/package.template.json @@ -0,0 +1,22 @@ +{ + "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/sample-app/typescript/tsconfig.json b/packages/aws-cdk/lib/init-templates/sample-app/typescript/tsconfig.json new file mode 100644 index 0000000000000..7520c5f08f852 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/tsconfig.json @@ -0,0 +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 + } +}