Skip to content

Commit

Permalink
feat(@whook/example): add AWS build to @whook/example
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Mar 6, 2020
1 parent 969c616 commit a061bd8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/whook-example/bin/build.js
@@ -0,0 +1,5 @@
#! /usr/bin/env node

const { runBuild } = require('../dist/index');

runBuild();
10 changes: 8 additions & 2 deletions packages/whook-example/package.json
Expand Up @@ -29,7 +29,8 @@
"childPackage": true,
"files": "'src/**/*.ts'",
"ignore": [
"dist"
"dist",
"builds"
],
"bundleFiles": [
"bin",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/whook-example/src/config/common/config.ts
Expand Up @@ -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';
Expand All @@ -15,6 +16,7 @@ export type AppConfigs = WhookConfigs &
WhookAuthorizationConfig &
WhookSwaggerUIConfig &
CORSConfig &
WhookCompilerConfig &
APIConfig;

const CONFIG: AppConfigs = {
Expand Down
47 changes: 45 additions & 2 deletions packages/whook-example/src/index.ts
Expand Up @@ -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<void> {
return runBaseBuild(innerPrepareEnvironment);
}

export async function prepareBuildEnvironment(
$: Knifecycle = new Knifecycle(),
): Promise<Knifecycle> {
$ = 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:
Expand Down Expand Up @@ -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
Expand All @@ -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 $;
}

0 comments on commit a061bd8

Please sign in to comment.