@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.
- package/README.md +1 -0
- package/dist/create-keystone-app.js +0 -0
- package/dist/create-module.js +584 -2
- package/package.json +22 -23
- package/template/.claude/skills/keystone-dev/SKILL.md +90 -103
- package/template/.claude/skills/keystone-dev/references/ADVANCED_PATTERNS.md +716 -0
- package/template/.claude/skills/keystone-dev/references/CHECKLIST.md +285 -0
- package/template/.claude/skills/keystone-dev/references/GOTCHAS.md +390 -0
- package/template/.claude/skills/keystone-dev/references/PATTERNS.md +605 -0
- package/template/.claude/skills/keystone-dev/references/TEMPLATES.md +2562 -384
- package/template/.codex/skills/keystone-dev/SKILL.md +90 -103
- package/template/.codex/skills/keystone-dev/references/ADVANCED_PATTERNS.md +716 -0
- package/template/.codex/skills/keystone-dev/references/CHECKLIST.md +285 -0
- package/template/.codex/skills/keystone-dev/references/GOTCHAS.md +390 -0
- package/template/.codex/skills/keystone-dev/references/PATTERNS.md +605 -0
- package/template/.codex/skills/keystone-dev/references/TEMPLATES.md +2562 -384
- package/template/README.md +8 -1
- package/template/docs/CONVENTIONS.md +11 -8
- package/template/package.json +3 -3
|
@@ -1,103 +1,90 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: keystone-dev
|
|
3
|
-
description:
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
##
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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` - 测试开发指南
|