From 0eb1cbccfbacb73f558788de3565c3e1bd4e83d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Guimar=C3=A3es?= Date: Tue, 8 Aug 2017 08:11:52 -0300 Subject: [PATCH 1/4] Adding aws-nodejs-typescript template --- lib/plugins/create/create.js | 1 + lib/plugins/create/create.test.js | 20 ++++++++++++++++++ .../templates/aws-nodejs-typescript/gitignore | 9 ++++++++ .../aws-nodejs-typescript/handler.ts | 3 +++ .../aws-nodejs-typescript/package.json | 17 +++++++++++++++ .../aws-nodejs-typescript/serverless.yml | 21 +++++++++++++++++++ .../aws-nodejs-typescript/tsconfig.json | 5 +++++ .../aws-nodejs-typescript/webpack.config.js | 18 ++++++++++++++++ 8 files changed, 94 insertions(+) create mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/gitignore create mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/handler.ts create mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/package.json create mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml create mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json create mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index eb62cc843..58da7159d 100644 --- a/lib/plugins/create/create.js +++ b/lib/plugins/create/create.js @@ -9,6 +9,7 @@ const userStats = require('../../utils/userStats'); // class wide constants const validTemplates = [ 'aws-nodejs', + 'aws-nodejs-typescript', 'aws-python', 'aws-python3', 'aws-groovy-gradle', diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index f77496b3d..e6e717174 100644 --- a/lib/plugins/create/create.test.js +++ b/lib/plugins/create/create.test.js @@ -99,6 +99,26 @@ describe('Create', () => { }); }); + it('should generate scaffolding for "aws-nodejs-typescript" template', () => { + process.chdir(tmpDir); + create.options.template = 'aws-nodejs-typescript'; + + return create.create().then(() => { + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'serverless.yml'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'handler.ts'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'tsconfig.json'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'package.json'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, 'webpack.config.js'))) + .to.be.equal(true); + expect(create.serverless.utils.fileExistsSync(path.join(tmpDir, '.gitignore'))) + .to.be.equal(true); + }); + }); + it('should generate scaffolding for "aws-csharp" template', () => { process.chdir(tmpDir); create.options.template = 'aws-csharp'; diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/gitignore b/lib/plugins/create/templates/aws-nodejs-typescript/gitignore new file mode 100644 index 000000000..983749343 --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/gitignore @@ -0,0 +1,9 @@ +# package directories +node_modules +jspm_packages + +# Serverless directories +.serverless + +# Webpack directories +.webpack \ No newline at end of file diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/handler.ts b/lib/plugins/create/templates/aws-nodejs-typescript/handler.ts new file mode 100644 index 000000000..280d14b94 --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/handler.ts @@ -0,0 +1,3 @@ +export const hello = (event, context, cb) => cb(null, + { message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!', event } +); \ No newline at end of file diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/package.json b/lib/plugins/create/templates/aws-nodejs-typescript/package.json new file mode 100644 index 000000000..dd30cbaae --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/package.json @@ -0,0 +1,17 @@ +{ + "name": "aws-nodejs-typescript", + "version": "1.0.0", + "description": "Serverless webpack example using Typescript", + "main": "handler.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "devDependencies": { + "serverless-webpack": "^2.2.0", + "ts-loader": "^2.3.1", + "typescript": "^2.4.2", + "webpack": "^3.3.0" + }, + "author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)", + "license": "MIT" +} \ No newline at end of file diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml new file mode 100644 index 000000000..b3547ac3a --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml @@ -0,0 +1,21 @@ +service: serverless-webpack-typescript-example + +# Add the serverless-webpack plugin +plugins: + - serverless-webpack + +provider: + name: aws + runtime: nodejs6.10 + +functions: +# Example with LAMBDA-PROXY integration +# Invoking locally: +# sls webpack invoke -f hello + hello: + handler: handler.hello + events: + - http: + method: get + path: hello + integration: lambda diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json b/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json new file mode 100644 index 000000000..fe55281f9 --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "sourceMap": true + } +} \ No newline at end of file diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js b/lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js new file mode 100644 index 000000000..58534724e --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js @@ -0,0 +1,18 @@ +const path = require('path'); +// eslint-disable-next-line import/no-unresolved +const slsw = require('serverless-webpack'); + +module.exports = { + entry: slsw.lib.entries, + output: { + libraryTarget: 'commonjs', + path: path.join(__dirname, '.webpack'), + filename: '[name].js', + }, + target: 'node', + module: { + loaders: [ + { test: /\.ts(x?)$/, loader: 'ts-loader' }, + ], + }, +}; From c329e43320725f22d5098893dcfdf7ce9945625a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Guimar=C3=A3es?= Date: Tue, 8 Aug 2017 09:16:51 -0300 Subject: [PATCH 2/4] reprocess travis build From 3d9ee40a80da680420a4e751baba88cc564f1fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Guimar=C3=A3es?= Date: Tue, 15 Aug 2017 18:49:02 -0300 Subject: [PATCH 3/4] Add aws-nodejs-typescript to the list of supported templates --- docs/providers/aws/cli-reference/create.md | 1 + docs/providers/aws/guide/services.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/providers/aws/cli-reference/create.md b/docs/providers/aws/cli-reference/create.md index 6d2a2296c..ac328a6a7 100644 --- a/docs/providers/aws/cli-reference/create.md +++ b/docs/providers/aws/cli-reference/create.md @@ -41,6 +41,7 @@ To see a list of available templates run `serverless create --help` Most commonly used templates: - aws-nodejs +- aws-nodejs-typescript - aws-python - aws-python3 - aws-groovy-gradle diff --git a/docs/providers/aws/guide/services.md b/docs/providers/aws/guide/services.md index 05031edbf..481039954 100644 --- a/docs/providers/aws/guide/services.md +++ b/docs/providers/aws/guide/services.md @@ -51,6 +51,7 @@ serverless create --template aws-nodejs --path myService Here are the available runtimes for AWS Lambda: * aws-nodejs +* aws-nodejs-typescript * aws-python * aws-python3 * aws-groovy-gradle From 87c77336b999339493630b8d673601cc4ef9709a Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 21 Aug 2017 14:53:40 +0200 Subject: [PATCH 4/4] Minor fixes for consistency --- docker-compose.yml | 4 ++++ .../templates/aws-nodejs-typescript/serverless.yml | 9 +++++---- .../create/templates/aws-nodejs-typescript/tsconfig.json | 2 +- tests/templates/test_all_templates | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 227462503..c5191720a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,6 +51,10 @@ services: image: microsoft/dotnet:1.0.4-sdk volumes: - ./tmp/serverless-integration-test-aws-fsharp:/app + aws-nodejs-typescript: + image: node:6.10.3 + volumes: + - ./tmp/serverless-integration-test-aws-nodejs-typescript:/app google-nodejs: image: node:6.9.1 volumes: diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml index b3547ac3a..ec6923fd5 100644 --- a/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml +++ b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml @@ -1,4 +1,5 @@ -service: serverless-webpack-typescript-example +service: + name: aws-nodejs-typescript # Add the serverless-webpack plugin plugins: @@ -9,9 +10,9 @@ provider: runtime: nodejs6.10 functions: -# Example with LAMBDA-PROXY integration -# Invoking locally: -# sls webpack invoke -f hello + # Example with LAMBDA-PROXY integration + # Invoking locally: + # sls webpack invoke -f hello hello: handler: handler.hello events: diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json b/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json index fe55281f9..8415c58c4 100644 --- a/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json +++ b/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json @@ -2,4 +2,4 @@ "compilerOptions": { "sourceMap": true } -} \ No newline at end of file +} diff --git a/tests/templates/test_all_templates b/tests/templates/test_all_templates index b539c35d1..594db88a6 100755 --- a/tests/templates/test_all_templates +++ b/tests/templates/test_all_templates @@ -17,4 +17,5 @@ integration-test aws-scala-sbt sbt assembly integration-test aws-nodejs integration-test aws-python integration-test aws-python3 +integration-test aws-nodejs-typescript integration-test google-nodejs