birc-generator 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PROJECT.md +1 -1
- package/README.md +11 -55
- package/bin/birc.js +5 -3
- package/package.json +1 -1
- package/plopfile.js +5 -3
- package/project-docs/PROJECT.md.hbs +1 -1
- package/test.md +1 -1
package/PROJECT.md
CHANGED
|
@@ -48,7 +48,7 @@ anchor 就不要重寫整份設定;推測以後會用到的模組先不要做
|
|
|
48
48
|
|
|
49
49
|
## 慣例
|
|
50
50
|
|
|
51
|
-
**make 一次整組。** `make` 串 `makeStackActions`:Entity + DAO + Mapper + DTO + Service + Controller。`--migration` 生 `create_{table}_table`(Flyway SQL)。`--seed` 生 `XxxSeeder`(Java,走 DAO;`birc seed` 才執行)。單層指令共用同一組 actions,不另寫一份。`make:entity` 產出 Entity、`XxxDAO extends BaseDAO
|
|
51
|
+
**make 一次整組。** `make` 串 `makeStackActions`:Entity + DAO + Mapper + DTO + Service + Controller。`--migration` 生 `create_{table}_table`(Flyway SQL)。`--seed` 生 `XxxSeeder`(Java,走 DAO;`birc seed` 才執行)。單層指令共用同一組 actions,不另寫一份。`make:entity` 產出 Entity、`XxxDAO extends BaseDAO`。`--migration` / `--seed` 同 `make:model`;已有 Entity 就跳過,只補 SQL / Seeder。`make:model` 同 Entity + DAO;`--migration` / `--seed` 同上,`--controller` 生 Controller。`make:seeder BookSeeder` 只生 Seeder(寫 `Book` 也可以,結尾 `Seeder` 會剝掉再對 Entity)。`--soft-delete` 在 Entity 加 Hibernate `@SoftDelete(columnName = "deleted_at", strategy = TIMESTAMP)`,migration 加 `deleted_at TIMESTAMP NULL`;`deleteById` 不用改。不做 restore / withTrashed。`make:entity --dto` 與 `make:entity --mapper` 一併生 Mapper 與 Request / Response DTO(同一組檔)。`make:mapper` 連 Request / Response DTO,並把 MapStruct 依賴接到 `build.gradle` 的 dependency-anchor 後面(已有則跳過)。`make:service` 的 `XxxService extends BaseService`,CRUD 在 `BaseServiceImpl`;多出來的業務方法寫在 `XxxService` / `XxxServiceImpl`。指令是 `make:entity`,不是 `make::entity`。預設只生引入與初稿;加 `--example` 或 `--fields` 才生完整範例(CRUD、欄位、`@Column`)。`--example` 的 Entity 與 `make:migration` 一樣帶 `created_at` / `updated_at`(DB 填,JPA `insertable = false`),不進 CreateRequest。多模組時 Entity / DAO 落在 `databaseconfig`。路徑以 `.bircrc.json` 的 `entityPath` / `daoPath` 為準。
|
|
52
52
|
|
|
53
53
|
**例外走 ProjectException。** 基底是專案內的 `ProjectException`(`getErrorCode` / `getHttpStatus`),不是 starter 的 `BusinessException`。`create` 會生 `ProjectException`、`NotFoundException`、`ExceptionHandleController`、`web/Result`。`make:exception` 生的類別一律 `extends ProjectException`。Controller 回傳專案內 `Result<T>`,不引用 `tw.edu.ntub.birc.starter`。
|
|
54
54
|
|
package/README.md
CHANGED
|
@@ -21,17 +21,9 @@ CRUD 用 `birc make`。多模組目錄、`BaseDAO`、`ProjectException` 會先
|
|
|
21
21
|
|
|
22
22
|
## 安裝
|
|
23
23
|
|
|
24
|
-
需要 Node 18
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
`birc update` 會自己判斷來源。npm 裝的等同
|
|
29
|
-
`npm install -g birc-generator@latest`;`curl` / PowerShell 裝的都拉
|
|
30
|
-
GitLab 到 `~/.birc-generator`。
|
|
31
|
-
|
|
32
|
-
### npm
|
|
33
|
-
|
|
34
|
-
Win11、WSL、macOS、Linux 都可以。
|
|
24
|
+
需要 Node 18 以上。只走 npm。Win11、WSL、macOS、Linux 都可以。一般只要
|
|
25
|
+
裝全域的 `birc`,不必 clone。改產生器、或要跑還沒發到 npm 的 commit,才
|
|
26
|
+
clone。
|
|
35
27
|
|
|
36
28
|
```bash
|
|
37
29
|
npm install -g birc-generator
|
|
@@ -44,47 +36,12 @@ npm update -g birc-generator
|
|
|
44
36
|
npm uninstall -g birc-generator
|
|
45
37
|
```
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### curl | bash
|
|
52
|
-
|
|
53
|
-
給 macOS、Linux、WSL、Git Bash。程式放到 `~/.birc-generator`,並把
|
|
54
|
-
`birc` 寫進使用者自己的 bin。不需要 sudo。PowerShell 不要貼這條:內建
|
|
55
|
-
`curl` 是 `Invoke-WebRequest`,會報找不到參數 `-fsSL`。改用下面的
|
|
56
|
-
PowerShell 安裝。
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
curl -fsSL https://gitlab.ntubimdbirc.tw/lucashsu95/birc-generator/-/raw/main/install.sh | bash
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
關掉終端再開一次,跑 `birc --help`。之後更新用 `birc update`。還沒有
|
|
63
|
-
這個指令的舊安裝,再跑一次上面的 `install.sh`。
|
|
64
|
-
|
|
65
|
-
解除安裝:
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
curl -fsSL https://gitlab.ntubimdbirc.tw/lucashsu95/birc-generator/-/raw/main/uninstall.sh | bash
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### PowerShell
|
|
39
|
+
`birc update` 等同 `npm install -g birc-generator@latest`。使用時若偵測到
|
|
40
|
+
新版本,會問要不要更新。說不要的話,同一版本 24 小時內不會再問。不想檢查
|
|
41
|
+
就設 `BIRC_SKIP_UPDATE_CHECK=1`。CI 或不是互動終端也不會問。
|
|
72
42
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
`irm | iex` 在記憶體執行,通常不必改 ExecutionPolicy。
|
|
76
|
-
|
|
77
|
-
```powershell
|
|
78
|
-
irm https://gitlab.ntubimdbirc.tw/lucashsu95/birc-generator/-/raw/main/install.ps1 | iex
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
關掉終端再開一次,跑 `birc --help`。之後更新用 `birc update`。
|
|
82
|
-
|
|
83
|
-
解除安裝:
|
|
84
|
-
|
|
85
|
-
```powershell
|
|
86
|
-
irm https://gitlab.ntubimdbirc.tw/lucashsu95/birc-generator/-/raw/main/uninstall.ps1 | iex
|
|
87
|
-
```
|
|
43
|
+
以前用 `curl | bash` 或 PowerShell 裝到 `~/.birc-generator` 的,改裝 npm
|
|
44
|
+
全域套件,並自行刪掉那個目錄。
|
|
88
45
|
|
|
89
46
|
## 第一次用
|
|
90
47
|
|
|
@@ -162,11 +119,11 @@ ValidGroup、Spotless、注入 agent 文件),不再問。
|
|
|
162
119
|
| 指令 | 做什麼 |
|
|
163
120
|
| --- | --- |
|
|
164
121
|
| `birc create` | 開一個多模組 Spring Boot 4 專案。`--yes` 其餘用預設、不要問 |
|
|
165
|
-
| `birc update` | 更新本機 `birc
|
|
122
|
+
| `birc update` | 更新本機 `birc`(`npm install -g birc-generator@latest`) |
|
|
166
123
|
| `birc add` | 往既有專案加模組。沒帶名稱會互動勾選;`birc add email sentry` 直接加。`--force` 覆寫已選的已安裝 feature 檔 |
|
|
167
124
|
| `birc sync` | 用目前 template 覆寫全部已安裝 feature 的檔(不動 yml / gradle) |
|
|
168
125
|
| `birc make` | 一次生 Entity + DAO + Mapper + DTO + Service + Controller;加 `--migration` / `--seed` |
|
|
169
|
-
| `birc make:entity` | Entity、`XxxDAO`;加 `--dto`、`--mapper`、`--soft-delete`。已有檔要覆寫加 `--force` |
|
|
126
|
+
| `birc make:entity` | Entity、`XxxDAO`;加 `--migration` / `--seed` / `--dto`、`--mapper`、`--soft-delete`。已有檔要覆寫加 `--force`;只要表或 Seeder 可 `--migration` / `--seed`,不會覆寫 Entity |
|
|
170
127
|
| `birc make:model` | 同 `make:entity`;加 `--migration` / `--seed` / `--controller` / `--soft-delete` |
|
|
171
128
|
| `birc make:mapper` | Mapper 和 CreateRequest / Response |
|
|
172
129
|
| `birc make:service` | `XxxService extends BaseService`,CRUD 在 `BaseServiceImpl` |
|
|
@@ -295,8 +252,7 @@ npm run test:mutation
|
|
|
295
252
|
|
|
296
253
|
發版順序:先把改動推進 GitLab `main`,再改 `package.json` 的 `version`,
|
|
297
254
|
最後 `npm publish`。只推 GitLab、不 publish 的話,`npm install -g` 的人
|
|
298
|
-
|
|
299
|
-
`irm | iex` / `birc update` 會跟 npm 版本對不上。
|
|
255
|
+
拿不到新版。
|
|
300
256
|
|
|
301
257
|
## 接下來
|
|
302
258
|
|
package/bin/birc.js
CHANGED
|
@@ -28,7 +28,7 @@ const HELP_SECTIONS = [
|
|
|
28
28
|
note: '寫法是 make:種類 [名稱]。預設只生引入與初稿;加 --example 或 --fields 才有完整範例',
|
|
29
29
|
commands: [
|
|
30
30
|
['make', '一次生 Entity + DAO + Mapper + DTO + Service + Controller;--migration / --seed'],
|
|
31
|
-
['make:entity', 'Entity、XxxDAO(--dto / --mapper / --soft-delete)'],
|
|
31
|
+
['make:entity', 'Entity、XxxDAO(--migration / --seed / --dto / --mapper / --soft-delete)'],
|
|
32
32
|
['make:model', '同 make:entity;--migration / --seed / --controller / --soft-delete'],
|
|
33
33
|
['make:mapper', 'Mapper、CreateRequest、Response'],
|
|
34
34
|
['make:service', 'XxxService extends BaseService'],
|
|
@@ -174,8 +174,8 @@ function printHelp() {
|
|
|
174
174
|
` ${'--example'.padEnd(nameWidth + 2)}make:* 產出完整範例`,
|
|
175
175
|
` ${'--dto'.padEnd(nameWidth + 2)}make:entity 順便生 Mapper 與 DTO`,
|
|
176
176
|
` ${'--mapper'.padEnd(nameWidth + 2)}同 --dto`,
|
|
177
|
-
` ${'--migration'.padEnd(nameWidth + 2)}make / make:model 順便生 create_{table}_table`,
|
|
178
|
-
` ${'--seed'.padEnd(nameWidth + 2)}make / make:model 順便生 Java Seeder`,
|
|
177
|
+
` ${'--migration'.padEnd(nameWidth + 2)}make / make:entity / make:model 順便生 create_{table}_table`,
|
|
178
|
+
` ${'--seed'.padEnd(nameWidth + 2)}make / make:entity / make:model 順便生 Java Seeder`,
|
|
179
179
|
` ${'--controller'.padEnd(nameWidth + 2)}make:model 順便生 Controller`,
|
|
180
180
|
` ${'--soft-delete'.padEnd(nameWidth + 2)}make:entity / make:model 加 deleted_at 軟刪`,
|
|
181
181
|
` ${'--fields'.padEnd(nameWidth + 2)}make 的欄位,例如 title:String,startTime:LocalDateTime(有帶就當完整產出)`,
|
|
@@ -198,6 +198,8 @@ function printHelp() {
|
|
|
198
198
|
' birc make:entity User --mapper',
|
|
199
199
|
' birc make:entity User --example',
|
|
200
200
|
' birc make:entity User --fields title:String,startTime:LocalDateTime',
|
|
201
|
+
' birc make:entity Book --migration',
|
|
202
|
+
' birc make:entity Book --seed',
|
|
201
203
|
' birc make Book --fields title:String,author:String --migration --seed',
|
|
202
204
|
' birc make:entity User --force',
|
|
203
205
|
' birc make:model Flight --migration',
|
package/package.json
CHANGED
package/plopfile.js
CHANGED
|
@@ -1212,13 +1212,15 @@ module.exports = function (plop) {
|
|
|
1212
1212
|
});
|
|
1213
1213
|
|
|
1214
1214
|
plop.setGenerator('make:entity', {
|
|
1215
|
-
description: '產生 Entity 與 DAO;--dto / --mapper
|
|
1215
|
+
description: '產生 Entity 與 DAO;--migration / --seed / --dto / --mapper / --soft-delete',
|
|
1216
1216
|
prompts: [entityNamePrompt, fieldsPrompt],
|
|
1217
1217
|
actions(data) {
|
|
1218
|
-
const
|
|
1218
|
+
const extras = includeModelMigration(data) || includeModelSeed(data);
|
|
1219
|
+
const actions = makeEntityActions(data, { skipIfExists: extras });
|
|
1219
1220
|
if (includeMapperWithEntity(data)) {
|
|
1220
|
-
|
|
1221
|
+
actions.push(...makeMapperActions(data));
|
|
1221
1222
|
}
|
|
1223
|
+
appendMakeSqlActions(actions, data);
|
|
1222
1224
|
return actions;
|
|
1223
1225
|
}
|
|
1224
1226
|
});
|
|
@@ -58,7 +58,7 @@ DB → Entity → Mapper → XxxResponse → Result<T>
|
|
|
58
58
|
## 統一規範
|
|
59
59
|
|
|
60
60
|
- 例外丟 `ProjectException` 子類(例如 `NotFoundException`),由 `ExceptionHandleController` 轉成回應。Controller 不手動 try-catch 包錯誤訊息。
|
|
61
|
-
- 整組骨架用 `birc make`;單層用 `birc make:entity` / `make:model` / `make:mapper` / `make:service` / `make:controller` / `make:exception`。`make:entity` 只生 Entity 與 DAO;`--dto` 與 `--mapper` 一併生 Mapper 與 DTO。`make:model` 可加 `--migration` / `--seed` / `--controller`。`make` 也可加 `--migration` / `--seed`。`make:seeder BookSeeder` 生 Java Seeder。`--soft-delete` 用 Hibernate `@SoftDelete` 的 `deleted_at`,查詢自動排除已刪;不要自寫 `@SQLDelete`。預設是初稿,完整範例加 `--example` 或 `--fields`。`make:migration create_{table}_table` 讀對應 Entity 欄位寫進 SQL。`--seed` 生 Java Seeder,用 DAO 塞資料;`birc seed` 才執行。清空資料庫用 `birc db:wipe`。不要複製其他 Entity 的程式碼來改名。
|
|
61
|
+
- 整組骨架用 `birc make`;單層用 `birc make:entity` / `make:model` / `make:mapper` / `make:service` / `make:controller` / `make:exception`。`make:entity` 只生 Entity 與 DAO;`--migration` / `--seed` 同 `make:model`(已有 Entity 就跳過,只補 SQL / Seeder)。`--dto` 與 `--mapper` 一併生 Mapper 與 DTO。`make:model` 可加 `--migration` / `--seed` / `--controller`。`make` 也可加 `--migration` / `--seed`。`make:seeder BookSeeder` 生 Java Seeder。`--soft-delete` 用 Hibernate `@SoftDelete` 的 `deleted_at`,查詢自動排除已刪;不要自寫 `@SQLDelete`。預設是初稿,完整範例加 `--example` 或 `--fields`。`make:migration create_{table}_table` 讀對應 Entity 欄位寫進 SQL。`--seed` 生 Java Seeder,用 DAO 塞資料;`birc seed` 才執行。清空資料庫用 `birc db:wipe`。不要複製其他 Entity 的程式碼來改名。
|
|
62
62
|
- 欄位驗證用專案內 `validation/ValidGroup`。CRUD 用 `Create` / `Update`。`Delete` 給「刪除還要帶原因、確認碼、樂觀鎖 version」的 body。`Submit` 給草稿可少填、送審要全填(活動送審就是這組)。Controller 的 `@Validated` 與欄位 `groups` 對同一組。
|
|
63
63
|
- email / sso / oauth / validGroup 用 `birc add`,不要從別的專案抄設定。
|
|
64
64
|
- 格式化走 Spotless(`./gradlew spotlessApply`),不要另裝 Checkstyle。
|
package/test.md
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
- CLI dest:檔落在呼叫者目錄,不是 generator repo。
|
|
36
36
|
- 產出 Java 沒有 `tw.edu.ntub.birc.starter` / `birc-spring-boot-starter`。
|
|
37
37
|
- `make:entity --dto` / `--mapper` 與 `make:mapper` 同一組 Mapper + DTO;預設 `make:entity` 不生它們。
|
|
38
|
-
- `make --fields --migration --seed` 寫 CREATE TABLE 與 Java `XxxSeeder`,不生 seed SQL;`make:model --migration` 的表名跟 Entity `@Table`
|
|
38
|
+
- `make --fields --migration --seed` 寫 CREATE TABLE 與 Java `XxxSeeder`,不生 seed SQL;`make:model --migration` 的表名跟 Entity `@Table` 一致。已有 Entity 時 `make:entity --migration` / `--seed` 跳過 Java,只補 CREATE TABLE / `XxxSeeder`。
|
|
39
39
|
- `make:seeder` / `--seed` 讀既有 Entity 欄位寫進 `setXxx`;沒有欄位時 `run()` 是空的。`make:seeder BookSeeder` 生 `BookSeeder.java`,不是 `BookSeederSeeder`。
|
|
40
40
|
- `make:migration create_{table}_table` 讀既有 Entity 欄位寫進 SQL;找不到 Entity 時仍只有 `id`。
|
|
41
41
|
- `--soft-delete` 的 Entity 用 `deleted_at` + `SoftDeleteType.TIMESTAMP`;沒加 flag 的 Entity / migration 沒有這欄。
|