@robsun/create-keystone-app 0.2.13 → 0.2.15

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.
@@ -1,103 +1,90 @@
1
- ---
2
- name: keystone-dev
3
- description: 基于 Keystone 平台开发业务模块。当用户需要创建新模块、添加业务功能、实现 CRUD、审批流程、数据导入导出、文件上传时使用。Use when creating modules, adding features, implementing CRUD, approval workflows, import/export, or file upload for Keystone platform.
4
- ---
5
-
6
- # Keystone 业务模块开发
7
-
8
- 使用 Keystone 平台快速开发业务模块。
9
-
10
- ## 工作流程
11
-
12
- 1. **解析需求** 识别所需能力
13
- 2. **生成前端模块** routes.tsx, pages/, services/, types.ts, locales/
14
- 3. **生成后端模块** handler/, service/, repository/, migrations/, i18n/
15
- 4. **自动注册** → main.tsx + manifest.go + config.yaml
16
- 5. **配置多语言** → 前端翻译文件 + 后端翻译键常量
17
- 6. **输出调整建议**
18
- 7. **补测试并执行** → 见 references/testing.md
19
-
20
- ## 多语言最佳实践
21
-
22
- **前端**:
23
- - 所有用户可见文本必须使用 `t()` 翻译函数
24
- - 翻译键使用点记法:`{module}:{section}.{key}`
25
- - 避免硬编码文本,确保国际化覆盖率 100%
26
-
27
- **后端**:
28
- - 错误消息使用翻译键常量(keys.go)
29
- - API 响应消息根据请求语言返回
30
- - 使用 `i18n.T(c, key)` 获取翻译文本
31
-
32
- 详见 [docs/I18N.md](../../docs/I18N.md)。
33
-
34
- ## 能力选择矩阵
35
-
36
- 根据需求关键词选用对应能力:
37
-
38
- | 需求关键词 | 前端能力 | 后端能力 |
39
- |-----------|---------|---------|
40
- | 列表、查询 | ProTable + 过滤 + 分页 | ListHandler + Repository |
41
- | 表单、编辑 | ProForm + 验证 | CreateHandler + UpdateHandler |
42
- | 导入、批量 | DataImporter | ImportHandler + Job队列 |
43
- | 导出、下载 | DataExporter | ExportHandler + Job队列 |
44
- | 上传、附件 | FileUpload | UploadHandler + 存储服务 |
45
- | 审批、流程 | ApprovalFlowEditor | 审批引擎 |
46
- | 权限 | PermissionGuard | 权限中间件 |
47
-
48
- 审批流程与接入说明见 [references/approval.md](references/approval.md)。
49
- 测试清单见 [references/testing.md](references/testing.md)。
50
- 详细能力清单见 [references/CAPABILITIES.md](references/CAPABILITIES.md)。
51
- 代码模板见 [references/TEMPLATES.md](references/TEMPLATES.md)。
52
-
53
- ## 模块结构约定
54
-
55
- ### 前端模块
56
- ```
57
- apps/web/src/modules/{name}/
58
- ├── index.ts # registerModule()
59
- ├── routes.tsx # 路由 + 菜单 + 权限
60
- ├── pages/
61
- │ ├── List.tsx # ProTable
62
- │ ├── Detail.tsx
63
- │ └── Form.tsx # ProForm
64
- ├── services/api.ts
65
- ├── types.ts
66
- ├── locales/ # 多语言翻译
67
- │ ├── zh-CN/{module}.json
68
- │ └── en-US/{module}.json
69
- └── help/
70
- └── index.md
71
- ```
72
-
73
- ### 后端模块
74
- ```
75
- apps/server/internal/modules/{name}/
76
- ├── module.go
77
- ├── api/handler/
78
- ├── domain/models/
79
- ├── domain/service/
80
- ├── infra/repository/
81
- ├── i18n/ # 多语言翻译
82
- │ ├── i18n.go
83
- │ ├── keys.go
84
- │ └── locales/
85
- │ ├── zh-CN.json
86
- │ └── en-US.json
87
- └── bootstrap/migrations/
88
- ```
89
-
90
- ## 权限命名
91
-
92
- 格式: `{module}:{resource}:{action}`
93
-
94
- 动作: view | create | update | delete | manage | export | import | approve
95
-
96
- ## 注册步骤
97
-
98
- 生成代码后需完成以下注册(**缺一不可**):
99
-
100
- 1. **前端导入** `main.tsx`: `import './modules/{name}'`
101
- 2. **前端启用** `app.config.ts`: 添加到 `modules.enabled` 数组 ⚠️ **必须,否则菜单不显示**
102
- 3. **后端注册** `manifest.go`: `import {name}module "app/internal/modules/{name}"` + `Register({name}module.NewModule())`
103
- 4. **后端启用** `config.yaml`: 添加到 `modules.enabled`
1
+ ---
2
+ name: keystone-dev
3
+ description: Build and extend Keystone modules and features (frontend + backend) with consistent structure, permissions, i18n, help docs, and OpenAPI contracts. Use when adding new modules, routes, APIs, migrations, or updating the scaffold template in this repo.
4
+ ---
5
+ # Keystone Dev
6
+
7
+ ## Core workflow
8
+ 1) Identify the target app root: this repo's scaffold template or a generated app.
9
+ 2) Create or update the module using the generator or the Example module as the baseline.
10
+ 3) Add or update tests for new behavior before finishing implementation.
11
+ 4) Wire frontend routes, menus, permissions, help docs, and i18n.
12
+ 5) Wire backend module registration, permissions, i18n, routes, migrations, and seeds.
13
+ 6) Update contracts and types when APIs change.
14
+ 7) Run the relevant checks before finishing.
15
+
16
+ ## Module creation
17
+ - Use the generator when possible:
18
+ ```bash
19
+ pnpm create:module <module-name> [options]
20
+
21
+ Options:
22
+ --frontend-only Only generate the frontend module
23
+ --backend-only Only generate the backend module
24
+ --with-crud Include CRUD example code
25
+ --with-approval Include approval workflow code (implies --with-crud)
26
+ --skip-register Skip auto registration steps
27
+ ```
28
+ - Keep module names in kebab-case and consistent across frontend, backend, and permissions.
29
+ - Prefer copying the Example module if you need a manual template.
30
+
31
+ ## Approval workflow (--with-approval)
32
+ When using `--with-approval`, the generator creates:
33
+ - **Backend**: `domain/service/approval.go` (Submit/Cancel), `domain/service/callback.go` (OnApproved/OnRejected), `api/handler/approval.go`
34
+ - **Frontend**: `components/ApprovalActions.tsx` with status tags and action buttons
35
+ - **Model updates**: Adds `draft/pending/approved/rejected` statuses and `ApprovalInstanceID` field
36
+ - **I18n**: Approval-related translations in both languages
37
+ - **Routes**: `POST /:id/submit` and `POST /:id/cancel` endpoints
38
+
39
+ After generation, register the approval callback in `module.go`:
40
+ ```go
41
+ func (m *Module) RegisterApprovalCallback(reg *approval.CallbackRegistry) error {
42
+ return reg.Register(service.ApprovalBusinessType, service.New{Pascal}ApprovalCallback(m.repo))
43
+ }
44
+ ```
45
+
46
+ ## Frontend checklist (apps/web)
47
+ - Add module at `apps/web/src/modules/<module>`.
48
+ - In `index.ts`, call `loadModuleLocales` and `registerModule`.
49
+ - In `routes.tsx`, set `handle.menu`, `handle.permission`, `handle.helpKey`, and use `labelKey`/`breadcrumbKey` for i18n.
50
+ - Add help docs under `apps/web/src/modules/<module>/help/**` and keep `helpKey` aligned.
51
+ - Add locale files in `apps/web/src/modules/<module>/locales/zh-CN/*.json` and `en-US/*.json`.
52
+
53
+ ## Backend checklist (apps/server)
54
+ - Add module at `apps/server/internal/modules/<module>`.
55
+ - Implement the Module interface in `module.go` and keep DDD layering (`api/`, `domain/`, `infra/`, `bootstrap/`).
56
+ - Register permissions with `CreateMenuI18n`/`CreateActionI18n` using `{module}:{resource}:{action}`.
57
+ - Register i18n in `RegisterI18n()` and provide `i18n/keys.go` + `i18n/locales/*.json`.
58
+ - Register the module in `apps/server/internal/modules/manifest.go`.
59
+ - Enable the module in `apps/server/config.yaml` (scaffold apps).
60
+
61
+ ## Testing development
62
+ - Backend: add unit tests in package folders (`*_test.go`) or in `tests/unit`/`tests/integration`/`tests/perf`.
63
+ - Frontend: add component or page tests alongside modules (e.g. `*.test.tsx`).
64
+ - Cover critical paths first (permissions, validation, and data mutations).
65
+
66
+ ## Contracts and API types
67
+ - Add or update OpenAPI specs under `contracts/NNN-<name>/`.
68
+ - Update `CONTRACT_MAPPING` in `scripts/generate-api-types.mjs` for new contract folders.
69
+ - Run `pnpm contracts:sync` and `pnpm -C packages/keystone-contracts generate` after contract changes.
70
+
71
+ ## Quality gates
72
+ - For scaffold changes: `pnpm -C packages/create-keystone-app/template test`.
73
+ - For contracts: `pnpm contracts:check` and `pnpm -C packages/keystone-contracts typecheck`.
74
+ - For backend changes: `go test ./...`.
75
+
76
+ ## Key references
77
+ - `packages/create-keystone-app/template/docs/CONVENTIONS.md`
78
+ - `packages/create-keystone-app/template/docs/CODE_STYLE.md`
79
+ - `packages/create-keystone-app/template/docs/I18N.md`
80
+ - `packages/create-keystone-app/template/apps/web/src/modules/example`
81
+ - `packages/create-keystone-app/template/apps/server/internal/modules/example`
82
+
83
+ ## Advanced templates (in `references/`)
84
+ - `TEMPLATES.md` - 基础 CRUD + 高级业务模板(多实体、审批流、导入导出、前端高级组件)
85
+ - `ADVANCED_PATTERNS.md` - 高级开发模式(跨模块依赖、状态机、缓存、并发控制、任务编排)
86
+ - `PATTERNS.md` - 后端开发模式(分页、事务、批量、软删除、预加载、审批集成)
87
+ - `CHECKLIST.md` - 模块开发完整自检清单
88
+ - `GOTCHAS.md` - 常见陷阱与解决方案
89
+ - `CAPABILITIES.md` - 平台完整能力清单
90
+ - `TESTING.md` - 测试开发指南