-
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.
Clean up the extension generator. Signed-off-by: Yaapa Hage <[email protected]>
- Loading branch information
1 parent
1de7194
commit a4d9b15
Showing
10 changed files
with
173 additions
and
24 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
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
26 changes: 20 additions & 6 deletions
26
packages/cli/generators/extension/templates/src/component.ts.ejs
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,9 +1,23 @@ | ||
import {Component, ProviderMap} from '@loopback/core'; | ||
import { | ||
Application, | ||
bind, | ||
Component, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
config, | ||
ContextTags, | ||
CoreBindings, | ||
inject, | ||
} from '@loopback/core'; | ||
import {<%= project.bindingsNamespace %>} from './keys' | ||
import {<%= project.defaultOptions %>, <%= project.optionsInterface %>} from './types'; | ||
|
||
// Configure the binding for <%= project.componentName %> | ||
@bind({tags: {[ContextTags.KEY]: <%= project.bindingsNamespace %>.COMPONENT}}) | ||
export class <%= project.componentName %> implements Component { | ||
constructor() {} | ||
|
||
providers?: ProviderMap = { | ||
}; | ||
|
||
constructor( | ||
@inject(CoreBindings.APPLICATION_INSTANCE) | ||
private application: Application, | ||
@config() | ||
private options: <%= project.optionsInterface %> = <%= project.defaultOptions %>, | ||
) {} | ||
} |
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 +1,3 @@ | ||
export * from './component'; | ||
export * from './keys'; | ||
export * from './types'; |
11 changes: 11 additions & 0 deletions
11
packages/cli/generators/extension/templates/src/keys.ts.ejs
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,11 @@ | ||
import {BindingKey, CoreBindings} from '@loopback/core'; | ||
import {<%= project.componentName %>} from './component'; | ||
|
||
/** | ||
* Binding keys used by this component. | ||
*/ | ||
export namespace <%= project.bindingsNamespace %> { | ||
export const COMPONENT = BindingKey.create<<%= project.componentName %>>( | ||
`${CoreBindings.COMPONENTS}.<%= project.componentName %>`, | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/cli/generators/extension/templates/src/types.ts.ejs
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,15 @@ | ||
/** | ||
* Interface defining the component's options object | ||
*/ | ||
export interface <%= project.optionsInterface %> { | ||
// Add the definitions here | ||
|
||
} | ||
|
||
/** | ||
* Default options for the component | ||
*/ | ||
export const <%= project.defaultOptions %>: <%= project.optionsInterface %> = { | ||
// Specify the values here | ||
|
||
}; |
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,3 +1,32 @@ | ||
# <%= project.name %> | ||
|
||
[![LoopBack](https://github.com/strongloop/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)[email protected])](http://loopback.io/) | ||
|
||
## Installation | ||
|
||
Install <%= project.componentName %> using `npm`; | ||
|
||
```sh | ||
$ npm install <%= project.name %> | ||
``` | ||
|
||
## Basic Use | ||
|
||
Configure and load <%= project.componentName %> in the application constructor | ||
as shown below. | ||
|
||
```ts | ||
import {<%= project.componentName %>, <%= project.optionsInterface %>, <%= project.defaultOptions %>} from '<%= project.name %>'; | ||
// ... | ||
export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) { | ||
constructor(options: ApplicationConfig = {}) { | ||
const opts: <%= project.optionsInterface %> = <%= project.defaultOptions %>; | ||
this.configure(<%= project.bindingsNamespace %>.COMPONENT).to(opts); | ||
// Put the configuration options here | ||
}); | ||
this.component(<%= project.componentName %>); | ||
// ... | ||
} | ||
// ... | ||
} | ||
``` |
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