Skip to content

Commit

Permalink
fix(cli): rename repository/service feature flags
Browse files Browse the repository at this point in the history
- Rename `--enableRepository` to `--repositories`
  (notice the plural form)
- Rename `--enableServices` to `--services`

This commit fixes the inconsistency where `--enableRepository` was
using the singular form, while `--enableServices` was using the plural
form.

It also improves the feature prompt so that the word "enable" is not
repeated twice.

Before:

    ? Select project build settings:
    ❯◉ Enable tslint
     ◉ Enable prettier
     ◉ Enable mocha
     ◉ Enable loopbackBuild
     ◉ Enable vscode
     ◉ Enable enableRepository
     ◉ Enable enableServices

After:

    ? Select features to enable in the project:
    ❯◉ Enable tslint
     ◉ Enable prettier
     ◉ Enable mocha
     ◉ Enable loopbackBuild
     ◉ Enable vscode
     ◉ Enable repositories
     ◉ Enable services
  • Loading branch information
bajtos committed Aug 31, 2018
1 parent ac011f8 commit c089299
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 25 deletions.
9 changes: 8 additions & 1 deletion docs/site/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ Answer the prompts as follows:
? Project description: Getting started tutorial
? Project root directory: (getting-started)
? Application class name: StarterApplication
? Select project build settings: Enable tslint, Enable prettier, Enable mocha, Enable loopbackBuild, Enable vscode
? Select features to enable in the project:
❯◉ Enable tslint
◉ Enable prettier
◉ Enable mocha
◉ Enable loopbackBuild
◉ Enable vscode
◉ Enable repositories
◉ Enable services
```

### Starting the project
Expand Down
18 changes: 10 additions & 8 deletions docs/site/soap-calculator-tutorial-scaffolding.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Let's start by creating the initial application by running the following
command:

```sh
lb4 app soap-calculator --enableRepository --enableServices
lb4 app soap-calculator --repositories --services
```

**Note:** The option **--enableRepository** instructs the **CLI** to include a
**Note:** The option **--repositories** instructs the **CLI** to include a
`RepositoryMixin` class in the application constructor which will be needed when
we create the datasource. The option **--enableServices** instructs the **CLI**
to include a `ServiceMixin` class in the application constructor which will be
we create the datasource. The option **--services** instructs the **CLI** to
include a `ServiceMixin` class in the application constructor which will be
needed to register our SOAP service client.

**LB4** will ask you a few questions _(you can leave the default options)_. The
Expand All @@ -33,20 +33,22 @@ application.ts file.
```

Next you will see a list of options for the build settings, if you did not
specify `--enableRepository` and `--enableServices` in the last command, then
you will see them in this list, make sure you enable both the repository and the
services for the application.
specify `--repositories` and `--services` in the last command, then you will see
them in this list, make sure you enable both the repository and the services for
the application.

**Note:** Enable all options, unless you know what you are doing, see
[The Getting Started guide](Getting-started.md) for more information.

```sh
? Select project build settings: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Select features to enable in the project:
❯◉ Enable tslint
◉ Enable prettier
◉ Enable mocha
◉ Enable loopbackBuild
◉ Enable vscode
◉ Enable repositories
◉ Enable services
```

#### Run the Application
Expand Down
4 changes: 3 additions & 1 deletion docs/site/todo-tutorial-scaffolding.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ $ lb4 app
? Project description: A todo list API made with LoopBack 4.
? Project root directory: (todo-list)
? Application class name: (TodoListApplication)
? Select project build settings: (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? Select features to enable in the project:
❯◉ Enable tslint
◉ Enable prettier
◉ Enable mocha
◉ Enable loopbackBuild
◉ Enable vscode
◉ Enable repositories
◉ Enable services
# npm will install dependencies now
Application todo-list was created in todo-list.
```
Expand Down
4 changes: 2 additions & 2 deletions examples/log-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Initialize your new extension project as follows: `lb4 extension`
- Project description: `An example extension project for LoopBack 4`
- Project root directory: `(loopback4-example-log-extension)`
- Component class name: `LogComponent`
- Select project build settings:
`Enable tslint, Enable prettier, Enable mocha, Enable loopbackBuild`
- Select features to enable in the project': `tslint`, `prettier`, `mocha`,
`loopbackBuild`

Now you can write the extension as follows:

Expand Down
16 changes: 8 additions & 8 deletions packages/cli/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module.exports = class AppGenerator extends ProjectGenerator {
// Note: arguments and options should be defined in the constructor.
constructor(args, opts) {
super(args, opts);
this.buildOptions.push('enableRepository');
this.buildOptions.push('enableServices');
this.buildOptions.push('repositories');
this.buildOptions.push('services');
}

_setupGenerator() {
Expand All @@ -23,12 +23,12 @@ module.exports = class AppGenerator extends ProjectGenerator {
description: 'Application class name',
});

this.option('enableRepository', {
this.option('repositories', {
type: Boolean,
description: 'Include repository imports and RepositoryMixin',
});

this.option('enableServices', {
this.option('services', {
type: Boolean,
description: 'Include service-proxy imports and ServiceMixin',
});
Expand Down Expand Up @@ -88,14 +88,14 @@ module.exports = class AppGenerator extends ProjectGenerator {

buildAppClassMixins() {
if (this.shouldExit()) return false;
const {enableRepository, enableServices} = this.projectInfo || {};
if (!enableRepository && !enableServices) return;
const {repositories, services} = this.projectInfo || {};
if (!repositories && !services) return;

let appClassWithMixins = 'RestApplication';
if (enableRepository) {
if (repositories) {
appClassWithMixins = `RepositoryMixin(${appClassWithMixins})`;
}
if (enableServices) {
if (services) {
appClassWithMixins = `ServiceMixin(${appClassWithMixins})`;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/generators/app/templates/src/application.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig} from '@loopback/core';
<% if (project.enableRepository) { -%>
<% if (project.repositories) { -%>
import {RepositoryMixin} from '@loopback/repository';
<% } -%>
import {RestApplication} from '@loopback/rest';
<% if (project.enableServices) { -%>
<% if (project.services) { -%>
import {ServiceMixin} from '@loopback/service-proxy';
<% } -%>
import {MySequence} from './sequence';
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/generators/project/templates/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"@loopback/core": "<%= project.dependencies['@loopback/core'] -%>",
"@loopback/dist-util": "<%= project.dependencies['@loopback/dist-util'] -%>",
"@loopback/openapi-v3": "<%= project.dependencies['@loopback/openapi-v3'] -%>",
<% if (project.enableRepository) { -%>
<% if (project.repositories) { -%>
"@loopback/repository": "<%= project.dependencies['@loopback/repository'] -%>",
<% } -%>
<% if (project.enableServices) { -%>
<% if (project.services) { -%>
"@loopback/rest": "<%= project.dependencies['@loopback/rest'] -%>",
"@loopback/service-proxy": "<%= project.dependencies['@loopback/service-proxy'] -%>"
<% } else { -%>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/project-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module.exports = class ProjectGenerator extends BaseGenerator {
const prompts = [
{
name: 'settings',
message: 'Select project build settings: ',
message: 'Select features to enable in the project',
type: 'checkbox',
choices: choices,
// Skip if all features are enabled by cli options
Expand Down

0 comments on commit c089299

Please sign in to comment.