From b6a7c34f506c04e342510a1af0e5254a2549c99c Mon Sep 17 00:00:00 2001 From: Paul Li Date: Sat, 11 May 2019 23:26:28 +1000 Subject: [PATCH] feat: Add javascript for init-templates/app --- packages/aws-cdk/.gitignore | 1 + .../app/javascript/.template.gitignore | 4 +++ .../app/javascript/.template.npmignore | 2 ++ .../init-templates/app/javascript/README.md | 7 +++++ .../app/javascript/bin/%name%.template.js | 9 ++++++ .../app/javascript/cdk.template.json | 3 ++ .../javascript/lib/%name%-stack.template.js | 17 +++++++++++ .../app/javascript/package.template.json | 21 ++++++++++++++ .../app/javascript/tsconfig.json | 28 +++++++++++++++++++ packages/aws-cdk/lib/init.ts | 6 ++++ packages/aws-cdk/test/test.init.ts | 10 +++++++ 11 files changed, 108 insertions(+) create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/.template.gitignore create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/.template.npmignore create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/README.md create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/bin/%name%.template.js create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/cdk.template.json create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/lib/%name%-stack.template.js create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/package.template.json create mode 100644 packages/aws-cdk/lib/init-templates/app/javascript/tsconfig.json diff --git a/packages/aws-cdk/.gitignore b/packages/aws-cdk/.gitignore index f15ab74e43d6f..1d6901e68114e 100644 --- a/packages/aws-cdk/.gitignore +++ b/packages/aws-cdk/.gitignore @@ -1,6 +1,7 @@ *.js *.js.map *.d.ts +!lib/init-templates/app/javascript/**/* node_modules dist diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/.template.gitignore b/packages/aws-cdk/lib/init-templates/app/javascript/.template.gitignore new file mode 100644 index 0000000000000..80cabb688731b --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/.template.gitignore @@ -0,0 +1,4 @@ +node_modules + +# CDK asset staging directory +.cdk.staging diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/.template.npmignore b/packages/aws-cdk/lib/init-templates/app/javascript/.template.npmignore new file mode 100644 index 0000000000000..d4928914d3e88 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/.template.npmignore @@ -0,0 +1,2 @@ +# CDK asset staging directory +.cdk.staging diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/README.md b/packages/aws-cdk/lib/init-templates/app/javascript/README.md new file mode 100644 index 0000000000000..5950bf1c8d08b --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/README.md @@ -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 diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/bin/%name%.template.js b/packages/aws-cdk/lib/init-templates/app/javascript/bin/%name%.template.js new file mode 100644 index 0000000000000..d5a4bdd629a79 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/bin/%name%.template.js @@ -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'); diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/cdk.template.json b/packages/aws-cdk/lib/init-templates/app/javascript/cdk.template.json new file mode 100644 index 0000000000000..ca1d40ed37e2d --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/cdk.template.json @@ -0,0 +1,3 @@ +{ + "app": "node bin/%name%.js" +} diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/lib/%name%-stack.template.js b/packages/aws-cdk/lib/init-templates/app/javascript/lib/%name%-stack.template.js new file mode 100644 index 0000000000000..73d6926e7cf37 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/lib/%name%-stack.template.js @@ -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 } diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/package.template.json b/packages/aws-cdk/lib/init-templates/app/javascript/package.template.json new file mode 100644 index 0000000000000..d8e685942f8e1 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/package.template.json @@ -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" + } +} diff --git a/packages/aws-cdk/lib/init-templates/app/javascript/tsconfig.json b/packages/aws-cdk/lib/init-templates/app/javascript/tsconfig.json new file mode 100644 index 0000000000000..45b40c310fd62 --- /dev/null +++ b/packages/aws-cdk/lib/init-templates/app/javascript/tsconfig.json @@ -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 + } +} diff --git a/packages/aws-cdk/lib/init.ts b/packages/aws-cdk/lib/init.ts index a36a047a9000c..f005fb1f259f2 100644 --- a/packages/aws-cdk/lib/init.ts +++ b/packages/aws-cdk/lib/init.ts @@ -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': @@ -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'; diff --git a/packages/aws-cdk/test/test.init.ts b/packages/aws-cdk/test/test.init.ts index 694327ca8dccd..6db55d2d21d45 100644 --- a/packages/aws-cdk/test/test.init.ts +++ b/packages/aws-cdk/test/test.init.ts @@ -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');