Skip to content

Commit

Permalink
feat(cdk init): empty 'app' template
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 #1124.

TO DO AFTER MERGING:

- [ ] Update workshop text to use new template
  • Loading branch information
rix0rrr committed Nov 19, 2018
1 parent 57700a7 commit 3e72389
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
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);
// The code that defines your stack goes here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"aws-cdk": "^%cdk-version%"
},
"dependencies": {
"@aws-cdk/aws-sns": "^%cdk-version%",
"@aws-cdk/aws-sqs": "^%cdk-version%",
"@aws-cdk/cdk": "^%cdk-version%"
}
}
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 3e72389

Please sign in to comment.