Skip to content

Commit

Permalink
feat(cli): Add javascript for init-templates/app (#2525)
Browse files Browse the repository at this point in the history
Fixes #398
  • Loading branch information
engineforce authored and Romain Marcadier-Muller committed May 13, 2019
1 parent 1e2a098 commit 2c5676a
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/aws-cdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.js
*.js.map
*.d.ts
!lib/init-templates/app/javascript/**/*
node_modules
dist

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules

# CDK asset staging directory
.cdk.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# CDK asset staging directory
.cdk.staging
7 changes: 7 additions & 0 deletions packages/aws-cdk/lib/init-templates/app/javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Useful commands

* `npm run test` check javascript error
* `npm run test:watch` watch for changes and check javascript error
* `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,9 @@
#!/usr/bin/env node

// @ts-ignore: Cannot find declaration file
require('source-map-support/register');
const cdk = require('@aws-cdk/cdk');
const { %name.PascalCased%Stack } = require('../lib/%name%-stack');

const app = new cdk.App();
new %name.PascalCased%Stack(app, '%name.PascalCased%Stack');
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 @@
const cdk = require('@aws-cdk/cdk');

class %name.PascalCased%Stack extends cdk.Stack {
/**
*
* @param {cdk.Construct} scope
* @param {string} id
* @param {cdk.StackProps=} props
*/
constructor(scope, id, props) {
super(scope, id, props);

// The code that defines your stack goes here
}
}

module.exports = { %name.PascalCased%Stack }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "%name%",
"version": "0.1.0",
"bin": {
"%name%": "bin/%name%.js"
},
"scripts": {
"test": "tsc",
"test:watch": "tsc -w",
"cdk": "cdk"
},
"devDependencies": {
"@types/node": "8.10.45",
"typescript": "^3.3.3333",
"aws-cdk": "^%cdk-version%"
},
"dependencies": {
"@aws-cdk/cdk": "^%cdk-version%",
"source-map-support": "^0.5.9"
}
}
28 changes: 28 additions & 0 deletions packages/aws-cdk/lib/init-templates/app/javascript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"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,
"allowJs": true,
"checkJs": true,
"noEmit": true
}
}
6 changes: 6 additions & 0 deletions packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ async function initializeGitRepository() {

async function postInstall(language: string, canUseNetwork: boolean) {
switch (language) {
case 'javascript':
return await postInstallJavascript(canUseNetwork);
case 'typescript':
return await postInstallTypescript(canUseNetwork);
case 'java':
Expand All @@ -248,6 +250,10 @@ async function postInstall(language: string, canUseNetwork: boolean) {
}
}

async function postInstallJavascript(canUseNetwork: boolean) {
return postInstallTypescript(canUseNetwork);
}

async function postInstallTypescript(canUseNetwork: boolean) {
const command = 'npm';

Expand Down
10 changes: 10 additions & 0 deletions packages/aws-cdk/test/test.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export = {
test.done();
},

async 'create a JavaScript app project'(test: Test) {
await cliInit('app', 'javascript', false);

// Check that package.json and bin/ got created in the current directory
test.equal(true, await fs.pathExists('package.json'));
test.equal(true, await fs.pathExists('bin'));

test.done();
},

async 'git directory does not throw off the initer!'(test: Test) {
fs.mkdirSync('.git');

Expand Down

0 comments on commit 2c5676a

Please sign in to comment.