Skip to content

Commit 2c5676a

Browse files
engineforceRomain Marcadier-Muller
authored and
Romain Marcadier-Muller
committed
feat(cli): Add javascript for init-templates/app (#2525)
Fixes #398
1 parent 1e2a098 commit 2c5676a

File tree

11 files changed

+108
-0
lines changed

11 files changed

+108
-0
lines changed

packages/aws-cdk/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.js
22
*.js.map
33
*.d.ts
4+
!lib/init-templates/app/javascript/**/*
45
node_modules
56
dist
67

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
3+
# CDK asset staging directory
4+
.cdk.staging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# CDK asset staging directory
2+
.cdk.staging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Useful commands
2+
3+
* `npm run test` check javascript error
4+
* `npm run test:watch` watch for changes and check javascript error
5+
* `cdk deploy` deploy this stack to your default AWS account/region
6+
* `cdk diff` compare deployed stack with current state
7+
* `cdk synth` emits the synthesized CloudFormation template
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
3+
// @ts-ignore: Cannot find declaration file
4+
require('source-map-support/register');
5+
const cdk = require('@aws-cdk/cdk');
6+
const { %name.PascalCased%Stack } = require('../lib/%name%-stack');
7+
8+
const app = new cdk.App();
9+
new %name.PascalCased%Stack(app, '%name.PascalCased%Stack');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"app": "node bin/%name%.js"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const cdk = require('@aws-cdk/cdk');
2+
3+
class %name.PascalCased%Stack extends cdk.Stack {
4+
/**
5+
*
6+
* @param {cdk.Construct} scope
7+
* @param {string} id
8+
* @param {cdk.StackProps=} props
9+
*/
10+
constructor(scope, id, props) {
11+
super(scope, id, props);
12+
13+
// The code that defines your stack goes here
14+
}
15+
}
16+
17+
module.exports = { %name.PascalCased%Stack }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "%name%",
3+
"version": "0.1.0",
4+
"bin": {
5+
"%name%": "bin/%name%.js"
6+
},
7+
"scripts": {
8+
"test": "tsc",
9+
"test:watch": "tsc -w",
10+
"cdk": "cdk"
11+
},
12+
"devDependencies": {
13+
"@types/node": "8.10.45",
14+
"typescript": "^3.3.3333",
15+
"aws-cdk": "^%cdk-version%"
16+
},
17+
"dependencies": {
18+
"@aws-cdk/cdk": "^%cdk-version%",
19+
"source-map-support": "^0.5.9"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2018",
4+
"module": "commonjs",
5+
"lib": [
6+
"es2016",
7+
"es2017.object",
8+
"es2017.string"
9+
],
10+
"declaration": true,
11+
"strict": true,
12+
"noImplicitAny": true,
13+
"strictNullChecks": true,
14+
"noImplicitThis": true,
15+
"alwaysStrict": true,
16+
"noUnusedLocals": true,
17+
"noUnusedParameters": true,
18+
"noImplicitReturns": true,
19+
"noFallthroughCasesInSwitch": false,
20+
"inlineSourceMap": true,
21+
"inlineSources": true,
22+
"experimentalDecorators": true,
23+
"strictPropertyInitialization": false,
24+
"allowJs": true,
25+
"checkJs": true,
26+
"noEmit": true
27+
}
28+
}

packages/aws-cdk/lib/init.ts

+6
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ async function initializeGitRepository() {
239239

240240
async function postInstall(language: string, canUseNetwork: boolean) {
241241
switch (language) {
242+
case 'javascript':
243+
return await postInstallJavascript(canUseNetwork);
242244
case 'typescript':
243245
return await postInstallTypescript(canUseNetwork);
244246
case 'java':
@@ -248,6 +250,10 @@ async function postInstall(language: string, canUseNetwork: boolean) {
248250
}
249251
}
250252

253+
async function postInstallJavascript(canUseNetwork: boolean) {
254+
return postInstallTypescript(canUseNetwork);
255+
}
256+
251257
async function postInstallTypescript(canUseNetwork: boolean) {
252258
const command = 'npm';
253259

packages/aws-cdk/test/test.init.ts

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ export = {
4848
test.done();
4949
},
5050

51+
async 'create a JavaScript app project'(test: Test) {
52+
await cliInit('app', 'javascript', false);
53+
54+
// Check that package.json and bin/ got created in the current directory
55+
test.equal(true, await fs.pathExists('package.json'));
56+
test.equal(true, await fs.pathExists('bin'));
57+
58+
test.done();
59+
},
60+
5161
async 'git directory does not throw off the initer!'(test: Test) {
5262
fs.mkdirSync('.git');
5363

0 commit comments

Comments
 (0)