diff --git a/packages/whook-example/bin/build.js b/packages/whook-example/bin/build.js new file mode 100644 index 00000000..8723f087 --- /dev/null +++ b/packages/whook-example/bin/build.js @@ -0,0 +1,5 @@ +#! /usr/bin/env node + +const { runBuild } = require('../dist/index'); + +runBuild(); diff --git a/packages/whook-example/package.json b/packages/whook-example/package.json index 53c59967..84bb2343 100644 --- a/packages/whook-example/package.json +++ b/packages/whook-example/package.json @@ -29,7 +29,8 @@ "childPackage": true, "files": "'src/**/*.ts'", "ignore": [ - "dist" + "dist", + "builds" ], "bundleFiles": [ "bin", @@ -50,6 +51,7 @@ "precz": "npm run compile", "prettier": "prettier --write 'src/**/*.ts'", "preversion": "npm run compile", + "build": "NODE_ENV=${NODE_ENV:-development} node bin/build", "start": "NODE_ENV=${NODE_ENV:-development} node bin/start", "test": "npm run jest", "types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist", @@ -72,9 +74,11 @@ "homepage": "https://github.com/nfroidure/whook", "dependencies": { "@whook/authorization": "^3.1.3", + "@whook/aws-lambda": "^3.1.3", "@whook/cli": "^3.1.3", "@whook/cors": "^3.1.3", "@whook/http-router": "^3.1.3", + "@whook/http-transaction": "^3.1.3", "@whook/swagger-ui": "^3.1.3", "@whook/whook": "^3.1.3", "common-services": "^6.2.0", @@ -94,11 +98,13 @@ "@babel/preset-typescript": "^7.8.3", "@babel/register": "^7.8.3", "@types/jest": "^24.9.0", + "babel-loader": "^8.0.6", + "babel-plugin-knifecycle": "^1.1.1", + "webpack": "4.41.5", "@typescript-eslint/eslint-plugin": "^2.16.0", "@typescript-eslint/parser": "^2.16.0", "axios": "^0.19.0", "babel-eslint": "^10.0.3", - "babel-plugin-knifecycle": "^1.1.1", "eslint": "^6.8.0", "eslint-plugin-prettier": "^3.1.2", "jest": "^24.9.0", diff --git a/packages/whook-example/src/config/common/config.ts b/packages/whook-example/src/config/common/config.ts index 6edbc3e0..9f6b9e24 100644 --- a/packages/whook-example/src/config/common/config.ts +++ b/packages/whook-example/src/config/common/config.ts @@ -2,6 +2,7 @@ import { WhookAuthorizationConfig } from '@whook/authorization'; import { WhookSwaggerUIConfig } from '@whook/swagger-ui'; import { CORSConfig } from '@whook/cors'; import { WhookConfigs } from '@whook/whook'; +import { WhookCompilerConfig } from '@whook/aws-lambda'; import { AuthenticationConfig } from '../../services/authentication'; import { APIConfig } from '../../services/API'; import { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/http-router'; @@ -15,6 +16,7 @@ export type AppConfigs = WhookConfigs & WhookAuthorizationConfig & WhookSwaggerUIConfig & CORSConfig & + WhookCompilerConfig & APIConfig; const CONFIG: AppConfigs = { diff --git a/packages/whook-example/src/index.ts b/packages/whook-example/src/index.ts index 6848ef95..4abea8f5 100644 --- a/packages/whook-example/src/index.ts +++ b/packages/whook-example/src/index.ts @@ -8,6 +8,43 @@ import { } from '@whook/whook'; import initHTTPRouter from '@whook/http-router'; import wrapHTTPRouterWithSwaggerUI from '@whook/swagger-ui'; +import { + runBuild as runBaseBuild, + prepareBuildEnvironment as prepareBaseBuildEnvironment, +} from '@whook/aws-lambda'; +import { initBuildConstants } from '@whook/aws-lambda'; +import { alsoInject } from 'knifecycle'; + +// The `runBuild` function is intended to build the +// project + +export async function runBuild( + innerPrepareEnvironment = prepareBuildEnvironment, +): Promise { + return runBaseBuild(innerPrepareEnvironment); +} + +export async function prepareBuildEnvironment( + $: Knifecycle = new Knifecycle(), +): Promise { + $ = await prepareEnvironment($); + $ = await prepareBaseBuildEnvironment($); + $.register( + constant('INITIALIZER_PATH_MAP', { + ENV: require.resolve('@whook/aws-lambda/dist/services/ENV'), + log: require.resolve('@whook/aws-lambda/dist/services/log'), + apm: require.resolve('@whook/http-transaction/dist/services/apm'), + obfuscator: require.resolve( + '@whook/http-transaction/dist/services/obfuscator', + ), + time: require.resolve('common-services/dist/time'), + delay: require.resolve('common-services/dist/delay'), + }), + ); + $.register(alsoInject(['API_DEFINITIONS'], initBuildConstants)); + + return $; +} // Per convention a Whook server main file must export // the following 3 functions to be composable: @@ -57,7 +94,7 @@ export async function prepareEnvironment( // This service loads the API definitions directly by // looking at your `src/handlers` folder. You can - // realease this behavior by removing this line + // release this behavior by removing this line $.register(initAPIDefinitions); // You have to declare the project main file directory @@ -70,7 +107,13 @@ export async function prepareEnvironment( $.register(constant('TRANSACTIONS', {})); // Setup your own whook plugins or avoid whook default by leaving it empty - $.register(constant('WHOOK_PLUGINS', ['@whook/cli', '@whook/whook'])); + $.register( + constant('WHOOK_PLUGINS', [ + '@whook/cli', + '@whook/whook', + '@whook/aws-lambda', + ]), + ); return $; }