-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(boot): initial project setup * feat(boot): bootstrapper implementation * feat(boot): controller booter implementation * feat(core): add boot, booters, and related interfaces / types * refactor(example-getting-started): use @loopback/boot * feat(cli): enable loopbackBoot as a option for new app projects * fix(cli): loopbackBoot should always be enabled and not an option * fix(boot): move bootOptions to ApplicationConfig * fix(boot): fix test name * fix(cli): add comments to template * style(core): update style for if statement * refactor: move boot related stuff from core to a mixin
- Loading branch information
Showing
43 changed files
with
1,576 additions
and
29 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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,25 @@ | ||
Copyright (c) IBM Corp. 2018. All Rights Reserved. | ||
Node module: @loopback/boot | ||
This project is licensed under the MIT License, full text below. | ||
|
||
-------- | ||
|
||
MIT license | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,97 @@ | ||
# @loopback/boot | ||
|
||
A convention based project Bootstrapper and Booters for LoopBack Applications | ||
|
||
# Overview | ||
|
||
A Booter is a Class that can be bound to an Application and is called | ||
to perform a task before the Application is started. A Booter may have multiple | ||
phases to complete its task. | ||
|
||
An example task of a Booter may be to discover and bind all artifacts of a | ||
given type. | ||
|
||
A Bootstrapper is needed to manage the Booters and execute them. This is provided | ||
in this package. For ease of use, everything needed is packages using a BootMixin. | ||
This Mixin will add convenience methods such as `boot` and `booter`, as well as | ||
properties needed for Bootstrapper such as `projectRoot`. The Mixin also adds the | ||
`BootComponent` to your `Application` which binds the `Bootstrapper` and default | ||
`Booters` made available by this package. | ||
|
||
## Installation | ||
|
||
```shell | ||
$ npm i @loopback/boot | ||
``` | ||
|
||
## Basic Use | ||
|
||
```ts | ||
import {Application} from '@loopback/core'; | ||
import {BootMixin} from '@loopback/boot'; | ||
class BootApp extends BootMixin(Application) {} | ||
|
||
const app = new BootApp(); | ||
app.projectRoot = __dirname; | ||
app.bootOptions = { | ||
controlles: { | ||
// Configure ControllerBooter Conventiones here. | ||
} | ||
} | ||
|
||
await app.boot(); | ||
await app.start(); | ||
``` | ||
|
||
### BootOptions | ||
List of Options available on BootOptions Object. | ||
|
||
|Option|Type|Description| | ||
|-|-|-| | ||
|`controllers`|`ArtifactOptions`|ControllerBooter convention options| | ||
|
||
### ArtifactOptions | ||
|
||
**Add Table for ArtifactOptions** | ||
|
||
### BootExecOptions | ||
|
||
**Add Table for BootExecOptions** | ||
|
||
## Available Booters | ||
|
||
### ControllerBooter | ||
|
||
#### Description | ||
Discovers and binds Controller Classes using `app.controller()`. | ||
|
||
#### Options | ||
The Options for this can be passed via `BootOptions` when calling `app.boot(options:BootOptions)`. | ||
|
||
The options for this are passed in a `controllers` object on `BootOptions`. | ||
|
||
Available Options on the `controllers` object on `BootOptions` are as follows: | ||
|
||
|Options|Type|Default|Description| | ||
|-|-|-|-| | ||
|`dirs`|`string | string[]`|`['controllers']`|Paths relative to projectRoot to look in for Controller artifacts| | ||
|`extensions`|`string | string[]`|`['.controller.js']`|File extensions to match for Controller artifacts| | ||
|`nested`|`boolean`|`true`|Look in nested directories in `dirs` for Controller artifacts| | ||
|`glob`|`string`||A `glob` pattern string. This takes precendence over above 3 options (which are used to make a glob pattern).| | ||
|
||
## Contributions | ||
|
||
- [Guidelines](https://github.com/strongloop/loopback-next/wiki/Contributing#guidelines) | ||
- [Join the team](https://github.com/strongloop/loopback-next/issues/110) | ||
|
||
## Tests | ||
|
||
Run `npm test` from the root folder. | ||
|
||
## Contributors | ||
|
||
See [all contributors](https://github.com/strongloop/loopback-next/graphs/contributors). | ||
|
||
## License | ||
|
||
MIT |
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,16 @@ | ||
{ | ||
"content": [ | ||
"index.ts", | ||
"src/booters/base-artifact.booter.ts", | ||
"src/booters/booter-utils.ts", | ||
"src/booters/controller.booter.ts", | ||
"src/booters/index.ts", | ||
"src/boot.component.ts", | ||
"src/boot.mixin.ts", | ||
"src/bootstrapper.ts", | ||
"src/index.ts", | ||
"src/interfaces.ts", | ||
"src/keys.ts" | ||
], | ||
"codeSectionDepth": 4 | ||
} |
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,6 @@ | ||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/boot | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export * from './dist'; |
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,6 @@ | ||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/boot | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
module.exports = require('./dist'); |
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,6 @@ | ||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/boot | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export * from './src'; |
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,58 @@ | ||
{ | ||
"name": "@loopback/boot", | ||
"version": "4.0.0-alpha.1", | ||
"description": "A collection of Booters for LoopBack 4 Applications", | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"acceptance": "lb-mocha \"DIST/test/acceptance/**/*.js\"", | ||
"build": "npm run build:dist", | ||
"build:current": "lb-tsc", | ||
"build:dist": "lb-tsc es2017", | ||
"build:apidocs": "lb-apidocs", | ||
"clean": "lb-clean loopback-boot*.tgz dist package api-docs", | ||
"prepublishOnly": "npm run build && npm run build:apidocs", | ||
"pretest": "npm run build:current", | ||
"integration": "lb-mocha \"DIST/test/integration/**/*.js\"", | ||
"test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/integration/**/*.js\" \"DIST/test/acceptance/**/*.js\"", | ||
"unit": "lb-mocha \"DIST/test/unit/**/*.js\"", | ||
"verify": "npm pack && tar xf loopback-boot*.tgz && tree package && npm run clean" | ||
}, | ||
"author": "IBM", | ||
"copyright.owner": "IBM Corp.", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@loopback/context": "^4.0.0-alpha.27", | ||
"@loopback/core": "^4.0.0-alpha.29", | ||
"@types/debug": "0.0.30", | ||
"@types/glob": "^5.0.34", | ||
"debug": "^3.1.0", | ||
"glob": "^7.1.2" | ||
}, | ||
"devDependencies": { | ||
"@loopback/build": "^4.0.0-alpha.10", | ||
"@loopback/openapi-v2": "^4.0.0-alpha.3", | ||
"@loopback/rest": "^4.0.0-alpha.18", | ||
"@loopback/testlab": "^4.0.0-alpha.20" | ||
}, | ||
"files": [ | ||
"README.md", | ||
"index.js", | ||
"index.js.map", | ||
"index.d.ts", | ||
"dist/src", | ||
"dist/index.js", | ||
"dist/index.js.map", | ||
"dist/index.d.ts", | ||
"api-docs", | ||
"src" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/strongloop/loopback-next.git" | ||
} | ||
} |
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,33 @@ | ||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/boot | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Bootstrapper} from './bootstrapper'; | ||
import {Component, Application, CoreBindings} from '@loopback/core'; | ||
import {inject, BindingScope} from '@loopback/context'; | ||
import {ControllerBooter} from './booters'; | ||
import {BootBindings} from './keys'; | ||
|
||
/** | ||
* BootComponent is used to export the default list of Booter's made | ||
* available by this module as well as bind the BootStrapper to the app so it | ||
* can be used to run the Booters. | ||
*/ | ||
export class BootComponent implements Component { | ||
// Export a list of default booters in the component so they get bound | ||
// automatically when this component is mounted. | ||
booters = [ControllerBooter]; | ||
|
||
/** | ||
* | ||
* @param app Application instance | ||
*/ | ||
constructor(@inject(CoreBindings.APPLICATION_INSTANCE) app: Application) { | ||
// Bound as a SINGLETON so it can be cached as it has no state | ||
app | ||
.bind(BootBindings.BOOTSTRAPPER_KEY) | ||
.toClass(Bootstrapper) | ||
.inScope(BindingScope.SINGLETON); | ||
} | ||
} |
Oops, something went wrong.