diff --git a/docker-compose.yml b/docker-compose.yml index a1e3a8d8a..d8c1287ec 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 aws-nodejs-ecma-script: image: node:6.10.3 volumes: diff --git a/docs/providers/aws/cli-reference/create.md b/docs/providers/aws/cli-reference/create.md index 9cfc7c5af..e27f01014 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-nodejs-ecma-script - aws-python - aws-python3 diff --git a/docs/providers/aws/guide/services.md b/docs/providers/aws/guide/services.md index 7e85f69f5..12c1389b8 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-nodejs-ecma-script * aws-python * aws-python3 diff --git a/lib/plugins/create/create.js b/lib/plugins/create/create.js index 3c8abb1d3..76efe88f8 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-nodejs-ecma-script', 'aws-python', 'aws-python3', diff --git a/lib/plugins/create/create.test.js b/lib/plugins/create/create.test.js index c67d793ad..90b03a5f4 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-nodejs-ecma-script" template', () => { process.chdir(tmpDir); create.options.template = 'aws-nodejs-ecma-script'; 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..ec6923fd5 --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.yml @@ -0,0 +1,22 @@ +service: + name: aws-nodejs-typescript + +# 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..8415c58c4 --- /dev/null +++ b/lib/plugins/create/templates/aws-nodejs-typescript/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "sourceMap": true + } +} 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' }, + ], + }, +}; diff --git a/tests/templates/test_all_templates b/tests/templates/test_all_templates index 876abc911..cf587e778 100755 --- a/tests/templates/test_all_templates +++ b/tests/templates/test_all_templates @@ -17,5 +17,6 @@ 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 aws-nodejs-ecma-script integration-test google-nodejs