-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build): isolate build functions
BREAKING CHANGE: Simply moving functions from `index.ts` to `build.ts`. fix #104
- Loading branch information
Showing
6 changed files
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#! /usr/bin/env node | ||
|
||
const { runBuild } = require('../dist/index'); | ||
const { runBuild } = require('../dist/build'); | ||
|
||
runBuild(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Knifecycle, { constant, alsoInject } from 'knifecycle'; | ||
import { initBuildConstants } from '@whook/whook'; | ||
import { prepareEnvironment } from '.'; | ||
import YError from 'yerror'; | ||
import type { Dependencies } from 'knifecycle'; | ||
|
||
// Per convention a Whook server build file must export | ||
// the following 2 functions to be composable: | ||
|
||
// The `runBuild` function is intended to build the | ||
// project | ||
export async function runBuild( | ||
innerPrepareEnvironment = prepareBuildEnvironment, | ||
): Promise<void> { | ||
throw new YError('E_NO_BUILD_IMPLEMENTED'); | ||
|
||
// Usually, here you call the installed build | ||
// return runBaseBuild(innerPrepareEnvironment); | ||
} | ||
|
||
// The `prepareBuildEnvironment` create the build | ||
// environment | ||
export async function prepareBuildEnvironment< | ||
T extends Knifecycle<Dependencies> | ||
>($: T = new Knifecycle() as T): Promise<T> { | ||
$ = await prepareEnvironment($); | ||
|
||
// Usually, here you call the installed build env | ||
// $ = await prepareBaseBuildEnvironment($); | ||
|
||
// The build often need to know were initializer | ||
// can be found to create a static build and | ||
// remove the need to create an injector | ||
$.register( | ||
constant('INITIALIZER_PATH_MAP', { | ||
ENV: '@whook/whook/dist/services/ProxyedENV', | ||
apm: '@whook/http-transaction/dist/services/apm', | ||
obfuscator: '@whook/http-transaction/dist/services/obfuscator', | ||
errorHandler: '@whook/http-router/dist/services/errorHandler', | ||
log: 'common-services/dist/log', | ||
time: 'common-services/dist/time', | ||
delay: 'common-services/dist/delay', | ||
}), | ||
); | ||
|
||
// Finally, some constants can be serialized instead of being | ||
// initialized in the target build saving some time at boot | ||
$.register(alsoInject(['API_DEFINITIONS'], initBuildConstants)); | ||
|
||
return $; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters