Skip to content

Commit cb4a8fc

Browse files
committed
feat(@whook/aws-lambda): add AWS lambda to the build
1 parent 58bb928 commit cb4a8fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2551
-28
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"coveralls": "^3.0.4",
5555
"cz-conventional-changelog": "^3.0.2",
5656
"lerna": "^3.19.0",
57-
"metapak": "^3.1.6",
57+
"metapak": "^3.1.7",
5858
"metapak-nfroidure": "9.8.2"
5959
},
6060
"contributors": [],

Diff for: packages/whook-authorization/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"eslint-plugin-prettier": "^3.1.2",
7575
"jest": "^24.9.0",
7676
"jsdoc-to-markdown": "^5.0.3",
77-
"metapak": "^3.1.6",
77+
"metapak": "^3.1.7",
7878
"metapak-nfroidure": "9.8.2",
7979
"prettier": "^1.19.1",
8080
"rimraf": "^3.0.1",

Diff for: packages/whook-aws-lambda/LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
Copyright © 2017 Nicolas Froidure
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the “Software”), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.

Diff for: packages/whook-aws-lambda/README.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
[//]: # ( )
2+
[//]: # (This file is automatically generated by a `metapak`)
3+
[//]: # (module. Do not change it except between the)
4+
[//]: # (`content:start/end` flags, your changes would)
5+
[//]: # (be overridden.)
6+
[//]: # ( )
7+
# @whook/aws-lambda
8+
> Build and deploy to AWS Lambda with Whook.
9+
10+
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/whook/blob/master/packages/whook-aws-lambda/LICENSE)
11+
[![NPM version](https://badge.fury.io/js/%40whook%2Faws-lambda.svg)](https://npmjs.org/package/@whook/aws-lambda)
12+
13+
14+
[//]: # (::contents:start)
15+
16+
This module is aimed to help you to deploy your Whook server
17+
to AWS Lambda.
18+
19+
## Testing commands
20+
21+
Building lambdas is done by creating the build script in your project `bin`
22+
folder :
23+
```sh
24+
cat "#! /usr/bin/env node
25+
26+
const { runBuild } = require('../dist/index');
27+
28+
runBuild();
29+
" > bin/build.js
30+
```
31+
32+
And add create the runBuild function in you `index.ts` main file :
33+
```diff
34+
+ import {
35+
+ initBuildConstants,
36+
+ runBuild as runBaseBuild,
37+
+ prepareBuildEnvironment as prepareBaseBuildEnvironment,
38+
+ } from '@whook/aws-lambda';
39+
+
40+
+ // The `runBuild` function is intended to build the
41+
+ // project
42+
+
43+
+ export async function runBuild(
44+
+ innerPrepareEnvironment = prepareBuildEnvironment,
45+
+ ): Promise<void> {
46+
+ return runBaseBuild(innerPrepareEnvironment);
47+
+ }
48+
+
49+
+ export async function prepareBuildEnvironment(
50+
+ $: Knifecycle = new Knifecycle(),
51+
+ ): Promise<Knifecycle> {
52+
+ $ = await prepareEnvironment($);
53+
+ $ = await prepareBaseBuildEnvironment($);
54+
+
55+
+ $.register(
56+
+ constant('INITIALIZER_PATH_MAP', {
57+
+ ENV: require.resolve('@whook/aws-lambda/dist/services/ENV'),
58+
+ log: require.resolve('@whook/aws-lambda/dist/services/log'),
59+
+ apm: require.resolve('@whook/http-transaction/dist/services/apm'),
60+
+ obfuscator: require.resolve(
61+
+ '@whook/http-transaction/dist/services/obfuscator',
62+
+ ),
63+
+ time: require.resolve('common-services/dist/time'),
64+
+ delay: require.resolve('common-services/dist/delay'),
65+
+ }),
66+
+ );
67+
+ $.register(alsoInject(['API_DEFINITIONS'], initBuildConstants));
68+
+
69+
+ return $;
70+
+ }
71+
```
72+
73+
Also add the following line in your `package.json` file :
74+
```diff
75+
scripts: {
76+
+ "build": "NODE_ENV=${NODE_ENV:-development} node bin/build",
77+
},
78+
devDependencies: {
79+
+ "@whook/aws-lambda": "^3.1.3",
80+
+ "@whook/http-transaction": "^3.1.3",
81+
+ "babel-loader": "^8.0.6",
82+
+ "babel-plugin-knifecycle": "^1.1.1",
83+
+ "webpack": "4.41.5",
84+
}
85+
```
86+
87+
To build your lambdas :
88+
```sh
89+
# Build all lambdas
90+
npm run compile && npm run build
91+
# Build only one lambda
92+
npm run compile && npm run build -- getPing
93+
```
94+
95+
You can easily test your lambda builds by adding `@whook/aws-lambda`
96+
to your `WHOOK_PLUGINS` list. It provides you some commands like
97+
the `testHTTPLambda` one:
98+
```sh
99+
npm run whook -- testHTTPLambda --name getPing
100+
```
101+
102+
[//]: # (::contents:end)
103+
104+
# Authors
105+
- [Nicolas Froidure](http://insertafter.com/en/index.html)
106+
107+
# License
108+
[MIT](https://github.com/nfroidure/whook/blob/master/packages/whook-aws-lambda/LICENSE)

Diff for: packages/whook-aws-lambda/package.json

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
{
2+
"name": "@whook/aws-lambda",
3+
"version": "3.1.3",
4+
"description": "Build and deploy to AWS Lambda with Whook.",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"metapak": {
8+
"configs": [
9+
"main",
10+
"readme",
11+
"eslint",
12+
"babel",
13+
"jest",
14+
"jsdocs",
15+
"typescript"
16+
],
17+
"data": {
18+
"childPackage": true,
19+
"files": "'src/**/*.ts'",
20+
"testsFiles": "'src/**/*.test.ts'",
21+
"ignore": [
22+
"dist"
23+
],
24+
"bundleFiles": [
25+
"dist",
26+
"src"
27+
]
28+
}
29+
},
30+
"author": {
31+
"name": "Nicolas Froidure",
32+
"email": "[email protected]",
33+
"url": "http://insertafter.com/en/index.html"
34+
},
35+
"license": "MIT",
36+
"repository": {
37+
"type": "git",
38+
"url": "https://github.com/nfroidure/whook.git"
39+
},
40+
"bugs": {
41+
"url": "https://github.com/nfroidure/whook/issues"
42+
},
43+
"homepage": "https://github.com/nfroidure/whook",
44+
"peerDependencies": {
45+
"babel-loader": "^8.0.6",
46+
"babel-plugin-knifecycle": "^1.1.1",
47+
"webpack": "4.41.5"
48+
},
49+
"dependencies": {
50+
"@whook/cli": "3.1.3",
51+
"@whook/http-router": "3.1.3",
52+
"@whook/whook": "3.1.3",
53+
"ajv": "^6.11.0",
54+
"camel-case": "^4.1.1",
55+
"common-services": "^6.2.0",
56+
"cpr": "3.0.1",
57+
"memfs": "3.0.4",
58+
"memory-fs": "0.5.0",
59+
"qs": "^6.9.1",
60+
"knifecycle": "^8.1.0",
61+
"openapi-types": "^1.3.5",
62+
"yerror": "^5.0.0"
63+
},
64+
"devDependencies": {
65+
"@babel/cli": "^7.8.3",
66+
"@babel/core": "^7.8.3",
67+
"@babel/plugin-proposal-class-properties": "^7.8.3",
68+
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
69+
"@babel/preset-env": "^7.8.3",
70+
"@babel/preset-typescript": "^7.8.3",
71+
"@babel/register": "^7.8.3",
72+
"@types/jest": "^24.9.0",
73+
"@typescript-eslint/eslint-plugin": "^2.16.0",
74+
"@typescript-eslint/parser": "^2.16.0",
75+
"babel-eslint": "^10.0.3",
76+
"babel-plugin-knifecycle": "^1.1.1",
77+
"eslint": "^6.8.0",
78+
"eslint-plugin-prettier": "^3.1.2",
79+
"jest": "^24.9.0",
80+
"jsdoc-to-markdown": "^5.0.3",
81+
"metapak": "^3.1.7",
82+
"metapak-nfroidure": "9.8.2",
83+
"prettier": "^1.19.1",
84+
"rimraf": "^3.0.1",
85+
"typescript": "^3.7.5"
86+
},
87+
"contributors": [],
88+
"engines": {
89+
"node": ">=8.12.0"
90+
},
91+
"files": [
92+
"dist",
93+
"src",
94+
"LICENSE",
95+
"README.md",
96+
"CHANGELOG.md"
97+
],
98+
"eslintConfig": {
99+
"extends": "eslint:recommended",
100+
"parserOptions": {
101+
"ecmaVersion": 2018,
102+
"sourceType": "module",
103+
"modules": true
104+
},
105+
"env": {
106+
"es6": true,
107+
"node": true,
108+
"jest": true,
109+
"mocha": true
110+
},
111+
"plugins": [
112+
"prettier"
113+
],
114+
"rules": {
115+
"prettier/prettier": "error"
116+
},
117+
"parser": "@typescript-eslint/parser",
118+
"ignorePatterns": [
119+
"*.d.ts"
120+
],
121+
"overrides": [
122+
{
123+
"files": [
124+
"*.ts"
125+
],
126+
"rules": {
127+
"no-unused-vars": [
128+
1,
129+
{
130+
"args": "none"
131+
}
132+
]
133+
}
134+
}
135+
]
136+
},
137+
"prettier": {
138+
"semi": true,
139+
"printWidth": 80,
140+
"singleQuote": true,
141+
"trailingComma": "all",
142+
"proseWrap": "always"
143+
},
144+
"babel": {
145+
"presets": [
146+
"@babel/typescript",
147+
[
148+
"@babel/env",
149+
{
150+
"targets": {
151+
"node": "8.12.0"
152+
}
153+
}
154+
]
155+
],
156+
"plugins": [
157+
"@babel/proposal-class-properties",
158+
"@babel/plugin-proposal-object-rest-spread",
159+
"babel-plugin-knifecycle"
160+
]
161+
},
162+
"jest": {
163+
"coverageReporters": [
164+
"lcov",
165+
"html"
166+
],
167+
"testPathIgnorePatterns": [
168+
"/node_modules/"
169+
],
170+
"roots": [
171+
"<rootDir>/src"
172+
]
173+
},
174+
"scripts": {
175+
"cli": "env NODE_ENV=${NODE_ENV:-cli}",
176+
"compile": "babel --extensions '.ts,.js' src --out-dir=dist --source-maps=true",
177+
"cover": "npm run jest -- --coverage",
178+
"doc": "echo \"# API\" > API.md; jsdoc2md undefined >> API.md && git add API.md",
179+
"jest": "NODE_ENV=test jest",
180+
"lint": "eslint 'src/**/*.ts'",
181+
"metapak": "metapak",
182+
"precz": "npm run compile",
183+
"prettier": "prettier --write 'src/**/*.ts'",
184+
"preversion": "npm run compile",
185+
"test": "npm run jest",
186+
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist"
187+
}
188+
}

0 commit comments

Comments
 (0)