@robsun/create-keystone-app 0.2.15 → 0.4.1
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 +46 -44
- package/dist/create-keystone-app.js +347 -10
- package/dist/create-module.js +1217 -1187
- package/package.json +1 -1
- package/template/.claude/skills/keystone-implement/SKILL.md +113 -0
- package/template/.claude/skills/keystone-implement/references/CHECKLIST.md +91 -0
- package/template/.claude/skills/keystone-implement/references/PATTERNS.md +1088 -0
- package/template/.claude/skills/keystone-implement/references/SCHEMA.md +135 -0
- package/template/.claude/skills/keystone-implement/references/TESTING.md +231 -0
- package/template/.claude/skills/keystone-requirements/SKILL.md +296 -0
- package/template/.claude/skills/keystone-requirements/references/CONFIRM_TEMPLATE.md +170 -0
- package/template/.claude/skills/keystone-requirements/references/SCHEMA.md +135 -0
- package/template/.eslintrc.js +3 -0
- package/template/.github/workflows/ci.yml +30 -0
- package/template/.github/workflows/release.yml +32 -0
- package/template/.golangci.yml +11 -0
- package/template/README.md +82 -81
- package/template/apps/server/README.md +8 -0
- package/template/apps/server/cmd/server/main.go +27 -185
- package/template/apps/server/config.example.yaml +31 -1
- package/template/apps/server/config.yaml +31 -1
- package/template/apps/server/go.mod +61 -19
- package/template/apps/server/go.sum +185 -32
- package/template/apps/server/internal/frontend/embed.go +3 -8
- package/template/apps/server/internal/modules/example/README.md +18 -0
- package/template/apps/server/internal/modules/example/api/handler/handler_test.go +9 -0
- package/template/apps/server/internal/modules/example/api/handler/item_handler.go +468 -165
- package/template/apps/server/internal/modules/example/bootstrap/seeds/item.go +217 -8
- package/template/apps/server/internal/modules/example/domain/models/item.go +40 -7
- package/template/apps/server/internal/modules/example/domain/service/approval_callback.go +68 -0
- package/template/apps/server/internal/modules/example/domain/service/approval_schema.go +41 -0
- package/template/apps/server/internal/modules/example/domain/service/errors.go +20 -22
- package/template/apps/server/internal/modules/example/domain/service/item_service.go +267 -7
- package/template/apps/server/internal/modules/example/domain/service/item_service_test.go +281 -0
- package/template/apps/server/internal/modules/example/i18n/keys.go +32 -20
- package/template/apps/server/internal/modules/example/i18n/locales/en-US.json +30 -18
- package/template/apps/server/internal/modules/example/i18n/locales/zh-CN.json +30 -18
- package/template/apps/server/internal/modules/example/infra/exporter/item_exporter.go +119 -0
- package/template/apps/server/internal/modules/example/infra/importer/item_importer.go +77 -0
- package/template/apps/server/internal/modules/example/infra/repository/item_repository.go +99 -49
- package/template/apps/server/internal/modules/example/module.go +171 -97
- package/template/apps/server/internal/modules/example/tests/integration_test.go +7 -0
- package/template/apps/server/internal/modules/manifest.go +7 -7
- package/template/apps/web/README.md +4 -2
- package/template/apps/web/package.json +1 -1
- package/template/apps/web/src/app.config.ts +8 -6
- package/template/apps/web/src/index.css +7 -3
- package/template/apps/web/src/main.tsx +2 -5
- package/template/apps/web/src/modules/example/help/en-US/faq.md +27 -0
- package/template/apps/web/src/modules/example/help/en-US/items.md +30 -0
- package/template/apps/web/src/modules/example/help/en-US/overview.md +31 -0
- package/template/apps/web/src/modules/example/help/zh-CN/faq.md +27 -0
- package/template/apps/web/src/modules/example/help/zh-CN/items.md +31 -0
- package/template/apps/web/src/modules/example/help/zh-CN/overview.md +32 -0
- package/template/apps/web/src/modules/example/locales/en-US/example.json +99 -32
- package/template/apps/web/src/modules/example/locales/zh-CN/example.json +85 -18
- package/template/apps/web/src/modules/example/pages/ExampleItemsPage.tsx +840 -237
- package/template/apps/web/src/modules/example/services/exampleItems.ts +79 -8
- package/template/apps/web/src/modules/example/types.ts +14 -1
- package/template/apps/web/src/modules/index.ts +1 -0
- package/template/apps/web/vite.config.ts +9 -3
- package/template/docs/CONVENTIONS.md +17 -17
- package/template/package.json +4 -5
- package/template/pnpm-lock.yaml +76 -5
- package/template/scripts/build.bat +15 -3
- package/template/scripts/build.sh +9 -3
- package/template/scripts/check-help.js +249 -0
- package/template/scripts/compress-assets.js +89 -0
- package/template/scripts/test.bat +23 -0
- package/template/scripts/test.sh +16 -0
- package/template/.claude/skills/keystone-dev/SKILL.md +0 -90
- package/template/.claude/skills/keystone-dev/references/ADVANCED_PATTERNS.md +0 -716
- package/template/.claude/skills/keystone-dev/references/APPROVAL.md +0 -121
- package/template/.claude/skills/keystone-dev/references/CAPABILITIES.md +0 -261
- package/template/.claude/skills/keystone-dev/references/CHECKLIST.md +0 -285
- package/template/.claude/skills/keystone-dev/references/GOTCHAS.md +0 -390
- package/template/.claude/skills/keystone-dev/references/PATTERNS.md +0 -605
- package/template/.claude/skills/keystone-dev/references/TEMPLATES.md +0 -2710
- package/template/.claude/skills/keystone-dev/references/TESTING.md +0 -44
- package/template/.codex/skills/keystone-dev/SKILL.md +0 -90
- package/template/.codex/skills/keystone-dev/references/ADVANCED_PATTERNS.md +0 -716
- package/template/.codex/skills/keystone-dev/references/APPROVAL.md +0 -121
- package/template/.codex/skills/keystone-dev/references/CAPABILITIES.md +0 -261
- package/template/.codex/skills/keystone-dev/references/CHECKLIST.md +0 -285
- package/template/.codex/skills/keystone-dev/references/GOTCHAS.md +0 -390
- package/template/.codex/skills/keystone-dev/references/PATTERNS.md +0 -605
- package/template/.codex/skills/keystone-dev/references/TEMPLATES.md +0 -2710
- package/template/.codex/skills/keystone-dev/references/TESTING.md +0 -44
- package/template/apps/server/internal/app/routes/module_routes.go +0 -16
- package/template/apps/server/internal/app/routes/routes.go +0 -226
- package/template/apps/server/internal/app/startup/startup.go +0 -74
- package/template/apps/server/internal/frontend/handler.go +0 -122
- package/template/apps/server/internal/modules/registry.go +0 -145
- package/template/apps/web/src/modules/example/help/faq.md +0 -23
- package/template/apps/web/src/modules/example/help/items.md +0 -26
- package/template/apps/web/src/modules/example/help/overview.md +0 -25
package/package.json
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: keystone-implement
|
|
3
|
+
description: 根据需求文档实现 Keystone 模块。支持新增模块和迭代更新。触发词:实现模块、开发功能、REQ-XXX、添加字段、修改功能。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Keystone Implement
|
|
7
|
+
|
|
8
|
+
**⚠️ 执行规则**:
|
|
9
|
+
1. 必须使用 `TodoWrite` 创建任务列表,包含所有 🔴 MUST 步骤
|
|
10
|
+
2. 所有 🔴 MUST 步骤必须按顺序执行,不得跳过
|
|
11
|
+
3. 每个步骤完成后必须在 TodoWrite 中标记为 completed
|
|
12
|
+
4. 🟢 OPTIONAL 步骤可根据实际需求选择执行
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 模式判断
|
|
17
|
+
|
|
18
|
+
| 场景 | 模式 | 特征 |
|
|
19
|
+
|------|------|------|
|
|
20
|
+
| 创建新模块 | 新增 | 模块目录不存在 |
|
|
21
|
+
| 修改现有模块 | 迭代 | 模块目录已存在 |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 新增模式
|
|
26
|
+
|
|
27
|
+
**输入**: `requirements/REQ-{序号}-{module}.yaml`(completeness: approved)
|
|
28
|
+
|
|
29
|
+
### 流程
|
|
30
|
+
|
|
31
|
+
**⚠️ 重要**:开始执行前必须使用 `TodoWrite` 创建任务列表,包含以下所有 🔴 MUST 步骤。
|
|
32
|
+
|
|
33
|
+
1. 🔴 **MUST: 解析需求** → 提取 module.name, fields, features
|
|
34
|
+
2. 🔴 **MUST: 生成代码** → 按 `PATTERNS.md` 生成(含高级模式如审批/分页等)
|
|
35
|
+
3. 🔴 **MUST: 模块注册** → 更新 manifest.go, config.yaml, main.tsx
|
|
36
|
+
4. 🔴 **MUST: 构建验证** → `go build ./...` + `pnpm typecheck`
|
|
37
|
+
5. 🔴 **MUST: 测试** → 参考 `TESTING.md`,执行测试命令并确保通过
|
|
38
|
+
6. 🔴 **MUST: 验收** → 参考 `CHECKLIST.md`,逐项检查
|
|
39
|
+
|
|
40
|
+
**验证要求**:
|
|
41
|
+
- 所有 🔴 MUST 步骤必须执行并在 TodoWrite 中标记为 completed
|
|
42
|
+
- 🟢 OPTIONAL 步骤可根据实际需求选择执行
|
|
43
|
+
|
|
44
|
+
### 生成顺序
|
|
45
|
+
|
|
46
|
+
| 后端 | 前端 |
|
|
47
|
+
|------|------|
|
|
48
|
+
| B2 Model → B5 Errors → B6 Repo | F3 Types → F4 API |
|
|
49
|
+
| B4 Service → B3 Handler | F5 Page → F6 Locales |
|
|
50
|
+
| B7-B9 i18n → B1 Module | F2 Routes → F1 Module |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 迭代模式
|
|
55
|
+
|
|
56
|
+
**输入**: 需求描述或更新后的 YAML
|
|
57
|
+
|
|
58
|
+
### 常见场景
|
|
59
|
+
|
|
60
|
+
| 变更类型 | 影响文件 |
|
|
61
|
+
|----------|----------|
|
|
62
|
+
| 添加字段 | Model, Handler Input, Service Input, Types, Page, Locales |
|
|
63
|
+
| 修改字段 | 同上 |
|
|
64
|
+
| 添加 API | Handler, Service, Repository, Routes, API Service |
|
|
65
|
+
| 修改业务逻辑 | Service |
|
|
66
|
+
| 添加高级功能 | 参考 `PATTERNS.md` 第六部分 |
|
|
67
|
+
|
|
68
|
+
### 流程
|
|
69
|
+
|
|
70
|
+
**⚠️ 重要**:开始执行前必须使用 `TodoWrite` 创建任务列表,包含以下所有 🔴 MUST 步骤。
|
|
71
|
+
|
|
72
|
+
1. 🔴 **MUST: 分析变更** → 确定影响范围
|
|
73
|
+
2. 🔴 **MUST: 定位文件** → 找到需要修改的文件
|
|
74
|
+
3. 🔴 **MUST: 增量修改** → 保持现有代码风格
|
|
75
|
+
4. 🔴 **MUST: 构建验证** → 确保编译通过
|
|
76
|
+
5. 🔴 **MUST: 测试** → 参考 `TESTING.md`,更新并执行相关测试
|
|
77
|
+
|
|
78
|
+
**验证要求**:
|
|
79
|
+
- 所有 🔴 MUST 步骤必须执行并在 TodoWrite 中标记为 completed
|
|
80
|
+
|
|
81
|
+
### 添加字段示例
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
需求:给 Customer 添加 phone 字段
|
|
85
|
+
|
|
86
|
+
1. Model: 添加 Phone string `gorm:"size:50" json:"phone"`
|
|
87
|
+
2. Handler: itemInput/itemUpdateInput 添加 Phone
|
|
88
|
+
3. Service: ItemInput/ItemUpdateInput 添加 Phone,Create/Update 处理
|
|
89
|
+
4. Types: Customer interface 添加 phone
|
|
90
|
+
5. Page: columns 和 Form.Item 添加 phone
|
|
91
|
+
6. Locales: fields.phone 添加翻译
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 构建验证
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
cd apps/server && go build ./...
|
|
100
|
+
pnpm -C apps/web typecheck
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**错误处理**:错误信息 → 对照 PATTERNS.md → 修复 → 重新验证
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 参考文档
|
|
108
|
+
|
|
109
|
+
| 文档 | 内容 |
|
|
110
|
+
|------|------|
|
|
111
|
+
| `PATTERNS.md` | 架构 + 约定 + 基础模式 + 高级模式 |
|
|
112
|
+
| `TESTING.md` | 测试模板 |
|
|
113
|
+
| `CHECKLIST.md` | 验收清单 |
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Keystone 模块验收清单
|
|
2
|
+
|
|
3
|
+
## 后端检查
|
|
4
|
+
|
|
5
|
+
### 文件结构
|
|
6
|
+
- [ ] `module.go` - 实现所有 Module 接口
|
|
7
|
+
- [ ] `api/handler/` - CRUD Handler
|
|
8
|
+
- [ ] `domain/models/` - 模型 + TableName()
|
|
9
|
+
- [ ] `domain/service/` - Service + errors.go
|
|
10
|
+
- [ ] `infra/repository/` - Repository
|
|
11
|
+
- [ ] `i18n/` - keys.go + i18n.go + locales/
|
|
12
|
+
- [ ] `bootstrap/migrations/` - Migrate()
|
|
13
|
+
|
|
14
|
+
### Module 接口
|
|
15
|
+
- [ ] `Name()` 返回模块名
|
|
16
|
+
- [ ] `RegisterRoutes()` 注册路由
|
|
17
|
+
- [ ] `RegisterModels()` 返回模型
|
|
18
|
+
- [ ] `RegisterPermissions()` 注册权限
|
|
19
|
+
- [ ] `RegisterI18n()` 注册翻译
|
|
20
|
+
- [ ] `Migrate()` 执行迁移
|
|
21
|
+
|
|
22
|
+
### Handler
|
|
23
|
+
- [ ] nil 检查: `if h == nil || h.svc == nil`
|
|
24
|
+
- [ ] 租户隔离: `tenantID := resolveTenantID(c)`
|
|
25
|
+
- [ ] i18n 错误响应
|
|
26
|
+
|
|
27
|
+
### Service
|
|
28
|
+
- [ ] 输入验证
|
|
29
|
+
- [ ] 状态检查: `status.IsValid()`
|
|
30
|
+
- [ ] 返回 i18n 错误
|
|
31
|
+
|
|
32
|
+
### Repository
|
|
33
|
+
- [ ] 租户过滤: `WHERE tenant_id = ?`
|
|
34
|
+
- [ ] 上下文传递: `db.WithContext(ctx)`
|
|
35
|
+
|
|
36
|
+
## 前端检查
|
|
37
|
+
|
|
38
|
+
### 文件结构
|
|
39
|
+
- [ ] `index.ts` - registerModule + loadModuleLocales
|
|
40
|
+
- [ ] `routes.tsx` - 路由 + handle
|
|
41
|
+
- [ ] `types.ts` - 类型定义
|
|
42
|
+
- [ ] `services/` - API 调用
|
|
43
|
+
- [ ] `locales/` - zh-CN + en-US
|
|
44
|
+
|
|
45
|
+
### 路由配置
|
|
46
|
+
- [ ] `handle.menu.labelKey` - i18n 键
|
|
47
|
+
- [ ] `handle.menu.permission` - 权限
|
|
48
|
+
- [ ] `handle.permission` - 路由权限
|
|
49
|
+
|
|
50
|
+
### 组件
|
|
51
|
+
- [ ] `useTranslation('module')` - 正确 namespace
|
|
52
|
+
- [ ] `App.useApp()` - 获取 message
|
|
53
|
+
- [ ] `destroyOnHidden` - 不用 destroyOnClose
|
|
54
|
+
|
|
55
|
+
## 注册检查
|
|
56
|
+
|
|
57
|
+
- [ ] `manifest.go` - 导入和注册模块
|
|
58
|
+
- [ ] `config.yaml` - modules.enabled 包含模块
|
|
59
|
+
- [ ] `main.tsx` - 导入模块
|
|
60
|
+
- [ ] `app.config.ts` - modules.enabled 包含模块
|
|
61
|
+
|
|
62
|
+
## 测试检查
|
|
63
|
+
|
|
64
|
+
- [ ] Service 单元测试
|
|
65
|
+
- [ ] `go test ./...` 通过
|
|
66
|
+
- [ ] `pnpm -C apps/web typecheck` 通过
|
|
67
|
+
|
|
68
|
+
## 常见陷阱
|
|
69
|
+
|
|
70
|
+
| 问题 | 原因 | 解决 |
|
|
71
|
+
|------|------|------|
|
|
72
|
+
| 菜单不显示 | config 未启用 | 检查 `config.yaml` 和 `app.config.ts` |
|
|
73
|
+
| Handler panic | nil 检查缺失 | 添加 `if h == nil` |
|
|
74
|
+
| 数据泄露 | 缺租户过滤 | Repository 加 `tenant_id` 条件 |
|
|
75
|
+
| 翻译显示键名 | namespace 错误 | 检查 `useTranslation` 参数 |
|
|
76
|
+
| Modal 不重置 | 用了 destroyOnClose | 改用 `destroyOnHidden` |
|
|
77
|
+
| API 解构错误 | 多层 data | `response.data.data.items` |
|
|
78
|
+
| 权限不生效 | 未注册权限 | 检查 `RegisterPermissions` |
|
|
79
|
+
| i18n NO_INSTANCE | 从 `react-i18next` 导入 | 必须从 `@robsun/keystone-web-core` 导入 `useTranslation` |
|
|
80
|
+
| antd 主题失效 (--local) | antd 实例重复 | Vite config 添加 `dedupe: ['antd', '@ant-design/icons', '@ant-design/cssinjs']` |
|
|
81
|
+
| 页面滚动条异常 | CSS reset 缺失 | 确保 global.css 包含 `box-sizing: border-box` 和 `body { margin: 0 }` |
|
|
82
|
+
|
|
83
|
+
## 质量命令
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 后端
|
|
87
|
+
go build ./... && go test ./... && go vet ./...
|
|
88
|
+
|
|
89
|
+
# 前端
|
|
90
|
+
pnpm -C apps/web typecheck && pnpm -C apps/web lint
|
|
91
|
+
```
|