-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(cli): lb4 repository implementation #1659
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
Merged
marioestradarosa
merged 6 commits into
loopbackio:master
from
marioestradarosa:feat-add-lb-repository
Sep 19, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08797cc
feat(cli): add lb4 repository feature
marioestradarosa 2001ff6
feat(cli): ast-helper integration
marioestradarosa 499d31a
docs(cli): add documentation for lb4 repository
marioestradarosa a984ef5
feat(cli): add util shared functions and constants
marioestradarosa e2de6ce
feat(cli): add test for multiple repositories
marioestradarosa 88dbb87
feat(cli): change msg when no datasource or repository exists
marioestradarosa 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
This file contains hidden or 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,98 @@ | ||
| --- | ||
| lang: en | ||
| title: 'Repository generator' | ||
| keywords: LoopBack 4.0, LoopBack 4 | ||
| sidebar: lb4_sidebar | ||
| permalink: /doc/en/lb4/Repository-generator.html | ||
| --- | ||
|
|
||
| {% include content/generator-create-app.html lang=page.lang %} | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Adds a new | ||
| [Repository class (or multiple backed by the same datasource)](Repositories.md) | ||
| to a LoopBack application with one single command. | ||
|
|
||
| ```sh | ||
| lb4 repository [options] [<name>] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| `--datasource` : _(Optional)_ name of a valid datasource already created in | ||
| src/datasources | ||
|
|
||
| `--model` : _(Optional)_ name of a valid model already created in src/models | ||
|
|
||
| `--id` : _(Optional)_ name of the property serving as **ID** in the selected | ||
| model. If you supply this value, the CLI will not try to infer this value from | ||
| the selected model file. | ||
|
|
||
| ### Configuration file | ||
|
|
||
| This generator supports a config file with the following format, see the | ||
| Standard options below to see different ways you can supply this configuration | ||
| file. | ||
|
|
||
| ```ts | ||
| { | ||
| "name": "repositoryNameToBeGenerated", | ||
| "datasource": "validDataSourceName", | ||
| "model": "validDModelName", | ||
| "id": "anOptionalNameForID" | ||
| } | ||
| ``` | ||
|
|
||
| ### Notes | ||
|
|
||
| Service oriented datasources such as REST or SOAP are not considered valid in | ||
| this context and will not be presented to you in the selection list. | ||
|
|
||
| There should be at least one valid _(KeyValue or Persisted)_ data source and one | ||
| model already created in their respective directories. | ||
|
|
||
| {% include_relative includes/CLI-std-options.md %} | ||
|
|
||
| ### Arguments | ||
|
|
||
| `<name>` - Optional argument specifyng the respository name to be generated. In | ||
| case you select multiple models, the first model will take this argument for its | ||
| repository file name. | ||
|
|
||
| ### Interactive Prompts | ||
|
|
||
| The tool will prompt you for: | ||
|
|
||
| - **Please select the datasource.** _(name)_ If the name of the datasource had | ||
| been supplied from the command line, the prompt is skipped, otherwise it will | ||
| present you the list of available datasources to select one. It will use this | ||
| datasource to check what kind of repository it will generate. | ||
|
|
||
| - **Select the model(s) you want to generate a repository.** _(model)_ If the | ||
| name of the model had been supplied from the command line with `--model` | ||
| option and it is a valid model, then the prompt is skipped, otherwise it will | ||
| present the error `Error: No models found` in the console. | ||
|
|
||
| If no `--model` is supplied, then the it will present you with a valid list of | ||
| models from `src/models` directory and you will be able to select one or | ||
| multiple models. The tool will generate a repository for each of the selected | ||
| models. | ||
|
|
||
| **NOTE:** The tool will inspect each of the selected models and try to find | ||
| the name of the property serving as **ID** for the model. | ||
|
|
||
| - **Please enter the name of the ID property for _modelName_.** _(id)_ If the | ||
| CLI cannot find the corresponding ID property name for the model, it will | ||
| prompt you to enter a name here. If you don't specify any name, it will use | ||
| _id_ as the default one. | ||
|
|
||
| ### Output | ||
|
|
||
| Once all the prompts have been answered, the CLI will do the following for each | ||
| of the selected models. | ||
|
|
||
| - Create a Repository class as follows: | ||
| `/src/repositories/${modelName}.repository.ts` | ||
| - Update `/src/repositories/index.ts` to export the newly created Repository | ||
| class. |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Yay for this simplification!