Skip to content

Commit

Permalink
fix(cdk init): update 'app' init template (aws#1209)
Browse files Browse the repository at this point in the history
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 aws#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 aws#1128.

The 'lib' init template used 'QueueArn' but that no long exists.

Fixes aws#1214.
  • Loading branch information
rix0rrr authored Nov 20, 2018
1 parent 127bb59 commit 402cbc4
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 103 deletions.
31 changes: 31 additions & 0 deletions packages/aws-cdk/integ-tests/test-init-template.sh
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"

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();
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app": "node bin/%name%.js"
"app": "node bin/%name%.js"
}
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
}
}
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 packages/aws-cdk/lib/init-templates/app/typescript/tsconfig.json
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
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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 packages/aws-cdk/lib/init-templates/lib/typescript/tsconfig.json
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
}
}

4 changes: 4 additions & 0 deletions packages/aws-cdk/lib/init-templates/sample-app/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Example CDK Application with some constructs",
"aliases": ["sample", "example"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js
*.d.ts
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.ts
!*.d.ts
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
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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "node bin/%name%.js"
}
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);
}
}
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%"
}
}
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
}
}

0 comments on commit 402cbc4

Please sign in to comment.