-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cdk init): update 'app' init template (#1209)
To avoid people having to clear out their template from the generated topic and queue after they run 'cdk init app', make the 'app' template an empty CDK project. The original code has been moved to 'cdk init sample-app' (aliases: 'cdk init sample', 'cdk init example'). Fixes #1124. Also change the content of the templates. We recommend people write reusable constructs in 'lib' directories, and they should put stacks there as well. Change both init templates to reflect this change. Fixes #1128. The 'lib' init template used 'QueueArn' but that no long exists. Fixes #1214.
- Loading branch information
Showing
18 changed files
with
207 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
|
19 changes: 1 addition & 18 deletions
19
packages/aws-cdk/lib/init-templates/app/typescript/bin/%name%.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
2 changes: 1 addition & 1 deletion
2
packages/aws-cdk/lib/init-templates/app/typescript/cdk.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"app": "node bin/%name%.js" | ||
"app": "node bin/%name%.js" | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
40 changes: 18 additions & 22 deletions
40
packages/aws-cdk/lib/init-templates/app/typescript/package.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%" | ||
} | ||
} |
39 changes: 19 additions & 20 deletions
39
packages/aws-cdk/lib/init-templates/app/typescript/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 22 additions & 22 deletions
44
packages/aws-cdk/lib/init-templates/lib/typescript/package.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%" | ||
} | ||
} |
38 changes: 19 additions & 19 deletions
38
packages/aws-cdk/lib/init-templates/lib/typescript/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"description": "Example CDK Application with some constructs", | ||
"aliases": ["sample", "example"] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.js | ||
*.d.ts | ||
node_modules |
2 changes: 2 additions & 0 deletions
2
packages/aws-cdk/lib/init-templates/sample-app/typescript/.template.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.ts | ||
!*.d.ts |
7 changes: 7 additions & 0 deletions
7
packages/aws-cdk/lib/init-templates/sample-app/typescript/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
7 changes: 7 additions & 0 deletions
7
packages/aws-cdk/lib/init-templates/sample-app/typescript/bin/%name%.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
3 changes: 3 additions & 0 deletions
3
packages/aws-cdk/lib/init-templates/sample-app/typescript/cdk.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "node bin/%name%.js" | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/aws-cdk/lib/init-templates/sample-app/typescript/package.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/aws-cdk/lib/init-templates/sample-app/typescript/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |