-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: @loopback/boot #858
Merged
Merged
feat: @loopback/boot #858
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
84d8d85
feat(boot): initial project setup
virkt25 b274b57
feat(boot): bootstrapper implementation
virkt25 516733e
feat(boot): controller booter implementation
virkt25 8395fdb
feat(core): add boot, booters, and related interfaces / types
virkt25 0a9898f
refactor(example-getting-started): use @loopback/boot
virkt25 a5a975c
feat(cli): enable loopbackBoot as a option for new app projects
virkt25 5eaaacc
fix(cli): loopbackBoot should always be enabled and not an option
virkt25 fc6d978
fix(boot): move bootOptions to ApplicationConfig
virkt25 6a9b0dc
fix(boot): fix test name
virkt25 2a54c18
fix(cli): add comments to template
virkt25 edfe2ff
style(core): update style for if statement
virkt25 e55b757
refactor: move boot related stuff from core to a mixin
virkt25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this list is missing an entry for
booters
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
booters
is a part of theBootStrapper
config, not theControllerBooter
config (which is what this table represents).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right!