loopbackio / loopbackio/loopback-next

[CLI] Prevent usage of already used keywords

オープン
#2,052 コメント 8 件 リアクション 0 件 担当者 1 名 GitHub で見る

@erogleva がすでに取り組んでいます。

2020年10月9日 から。

CLI developer-experience good first issue Hacktoberfest help wanted
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

## Description / Steps to reproduce / Feature proposal

When using the CLI I can create a model named Entity, or Model. The model is generated but no warning will be emitted (this keyword is already used by Loopback).

## Current Behavior

The model/controller/datasource/... is generated.

```ts
import {Model, model, property} from '@loopback/repository';

@model()
export class Model extends Model {
constructor(data?: Partial) {
super(data);
}
}

```

## Expected Behavior

Multiple options here:

1. add warnings in the creation process
2. prevent the component (model/controller/...) from being created
1. by retrying
2. by exiting
3. modify the generated file , for a model e.g:

```ts
import * as repository from '@loopback/repository';

@repository.model()
export class Model extends repository.Model {
constructor(data?: Partial) {
super(data);
}
}
```

## Keywords to consider

For controllers: nothing (overwriting existing controllers is already handled)

For datasources: nothing (overwriting existing datasources is already handled)

For models:
- Entity
- Model

For repositories:
- Repository

For services: ?

For openapi: nothing

Anything else ?

## Acceptance criteria

Add a Yeoman prompt validator to reject model/repository/controller names that are the same as one of the built-in ones. This way, when a user enters invalid name, Yeoman will print an error and repeat the prompt.

- [ ] Enhance `ArtifactGenerator.promptArtifactName()` to allow subclasses (specific generators) to further customize the validation rules for artifact name. For example, we can introduce a protected property that subclasses can override.

https://github.com/strongloop/loopback-next/blob/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/lib/artifact-generator.js#L60

For each of the following generators, provide validation rule that will reject problematic names:

- [ ] [`lb4 controller`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/controller/index.js)
- [ ] [`lb4 datasource`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/datasource/index.js)
- [ ] [`lb4 interceptor`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/interceptor/index.js)
- [ ] [`lb4 model`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/model/index.js)
- [ ] [`lb4 observer`](https://github.com/strongloop/loopback-next/blob/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/observer/index.js)
- [ ] [`lb4 relation`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/relation/index.js)
- [ ] [`lb4 repository`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/repository/index.js)
- [ ] [`lb4 service`](https://github.com/strongloop/loopback-next/tree/752db84f3e6f4984c35c2fc65f54eacae23e002e/packages/cli/generators/service/index.js)

---

## 🎆 Hacktoberfest 2020

Greetings :wave: to all Hacktoberfest 2020 participants!

Here are few tips 👀 to make your start easier, see also #6456:

- Before you start working on this issue, please leave a comment to let others know.
- This issue consists of several tasks to work on, it may feel like a too big effort to undertake. Don't worry! It's perfectly fine to pick just one item from the list and leave the rest for somebody else. In fact, we prefer to have a dedicated pull request for each part, to make it easier for us to review the changes and get the pull request landed faster. Baby steps FTW! Remember, every little helps.
- If you are new to GitHub pull requests, then you can learn about the process in [Submitting a pull request to LoopBack 4](https://loopback.io/doc/en/lb4/submitting_a_pr.html).
- If this is your first contribution to LoopBack, then please take a look at our [Developer guide](https://loopback.io/doc/en/lb4/code-contrib-lb4.html)
- Feel free to ask for help in `#loopback-contributors` channel, you can join our Slack workspace [here](https://join.slack.com/t/loopbackio/shared_invite/zt-8lbow73r-SKAKz61Vdao~_rGf91pcsw).

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。