@robsun/create-keystone-app 0.2.13 → 0.4.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/README.md +46 -43
- package/dist/create-keystone-app.js +347 -10
- package/dist/create-module.js +1219 -607
- package/package.json +22 -23
- 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 +81 -73
- 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 +60 -18
- package/template/apps/server/go.sum +183 -31
- 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 +10 -7
- 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 -103
- 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/TEMPLATES.md +0 -532
- package/template/.claude/skills/keystone-dev/references/TESTING.md +0 -44
- package/template/.codex/skills/keystone-dev/SKILL.md +0 -103
- 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/TEMPLATES.md +0 -532
- 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
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
# Keystone 包完整能力清单
|
|
2
|
-
|
|
3
|
-
## 一、前端组件 (@robsun/keystone-web-core)
|
|
4
|
-
|
|
5
|
-
### 1. 应用与路由
|
|
6
|
-
```typescript
|
|
7
|
-
import { KeystoneApp, createKeystoneRouter } from '@robsun/keystone-web-core'
|
|
8
|
-
import { registerModule, registerRoutes, registerMenus, registerPermissions } from '@robsun/keystone-web-core'
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
### 2. 高级 UI 组件
|
|
12
|
-
```typescript
|
|
13
|
-
// 高级表格 - 过滤、分页、行选择、导出
|
|
14
|
-
import { ProTable } from '@robsun/keystone-web-core'
|
|
15
|
-
|
|
16
|
-
// 智能表单 - 自动验证、加载状态
|
|
17
|
-
import { ProForm } from '@robsun/keystone-web-core'
|
|
18
|
-
|
|
19
|
-
// 文件上传 - 拖拽、预览、多文件
|
|
20
|
-
import { FileUpload } from '@robsun/keystone-web-core'
|
|
21
|
-
|
|
22
|
-
// 数据导入向导
|
|
23
|
-
import { DataImporter, ImportWizard, ColumnMapper, ValidationResult } from '@robsun/keystone-web-core'
|
|
24
|
-
|
|
25
|
-
// 数据导出向导
|
|
26
|
-
import { DataExporter, ExportWizard } from '@robsun/keystone-web-core'
|
|
27
|
-
|
|
28
|
-
// 权限守卫
|
|
29
|
-
import { PermissionGuard } from '@robsun/keystone-web-core'
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### 3. 审批流系统
|
|
33
|
-
```typescript
|
|
34
|
-
import {
|
|
35
|
-
ApprovalFlowEditor, // 流程编辑器
|
|
36
|
-
ApprovalFlowCanvas, // 可视化画布
|
|
37
|
-
ApprovalNodeEditor, // 节点编辑
|
|
38
|
-
ConditionEditor, // 条件编辑
|
|
39
|
-
ApprovalStatus, // 状态展示
|
|
40
|
-
ApprovalAction, // 审批按钮
|
|
41
|
-
ApprovalHistory // 审批历史
|
|
42
|
-
} from '@robsun/keystone-web-core'
|
|
43
|
-
```
|
|
44
|
-
审批流程与接入说明见 [approval.md](approval.md)。
|
|
45
|
-
|
|
46
|
-
### 4. 帮助系统
|
|
47
|
-
```typescript
|
|
48
|
-
import {
|
|
49
|
-
HelpButton, HelpDrawer, HelpSearch, HelpContent,
|
|
50
|
-
useCurrentHelpKey, useHelpSearch
|
|
51
|
-
} from '@robsun/keystone-web-core'
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 5. 布局与主题
|
|
55
|
-
```typescript
|
|
56
|
-
import { MainLayout, antdTheme, useLayoutStore } from '@robsun/keystone-web-core'
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### 6. 认证授权
|
|
60
|
-
```typescript
|
|
61
|
-
import { useAuthStore, useAuth, matchesPermission } from '@robsun/keystone-web-core'
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### 7. 运行时服务
|
|
65
|
-
```typescript
|
|
66
|
-
import { api, setApiBaseUrl } from '@robsun/keystone-web-core'
|
|
67
|
-
import { createExportJob, createImportJob } from '@robsun/keystone-web-core'
|
|
68
|
-
import { listNotifications, markNotificationRead, fetchUnreadCount } from '@robsun/keystone-web-core'
|
|
69
|
-
import { getJob, listJobs } from '@robsun/keystone-web-core'
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### 8. 多语言 (i18n)
|
|
73
|
-
```typescript
|
|
74
|
-
// 翻译 Hook
|
|
75
|
-
import { useTranslation } from 'react-i18next'
|
|
76
|
-
|
|
77
|
-
// 使用示例
|
|
78
|
-
const { t } = useTranslation()
|
|
79
|
-
const title = t('module:key') // 命名空间:键
|
|
80
|
-
const description = t('common:actions.save')
|
|
81
|
-
|
|
82
|
-
// 平台多语言配置
|
|
83
|
-
import { getKeystoneConfig } from '@robsun/keystone-web-core'
|
|
84
|
-
const locale = getKeystoneConfig().ui?.i18n?.defaultLocale // 'zh-CN' | 'en-US'
|
|
85
|
-
|
|
86
|
-
// dayjs 本地化同步(自动完成)
|
|
87
|
-
import dayjs from 'dayjs'
|
|
88
|
-
dayjs.locale(getKeystoneConfig().ui?.locale?.dayjs ?? 'zh-cn')
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
**翻译文件组织**:
|
|
92
|
-
```
|
|
93
|
-
src/modules/{module}/locales/
|
|
94
|
-
├── zh-CN/
|
|
95
|
-
│ └── {namespace}.json
|
|
96
|
-
└── en-US/
|
|
97
|
-
└── {namespace}.json
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
**命名空间约定**:
|
|
101
|
-
- `common` - 通用文案(按钮、操作、状态等)
|
|
102
|
-
- `auth` - 认证相关
|
|
103
|
-
- `system` - 系统管理
|
|
104
|
-
- `{module}` - 业务模块专属翻译
|
|
105
|
-
|
|
106
|
-
### 9. Hooks
|
|
107
|
-
```typescript
|
|
108
|
-
import { useListState } from '@robsun/keystone-web-core'
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### 10. 类型
|
|
112
|
-
```typescript
|
|
113
|
-
import type { ApiResponse, PaginatedData, PaginatedResponse } from '@robsun/keystone-web-core'
|
|
114
|
-
import type { Permission, ModuleName, Action } from '@robsun/keystone-web-core'
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## 二、后端能力 (Go)
|
|
118
|
-
|
|
119
|
-
### 1. 模块系统
|
|
120
|
-
```go
|
|
121
|
-
type Module interface {
|
|
122
|
-
Name() string
|
|
123
|
-
RegisterRoutes(r *gin.RouterGroup)
|
|
124
|
-
RegisterPermissions() []Permission
|
|
125
|
-
Migrate(db *gorm.DB) error
|
|
126
|
-
Seed(db *gorm.DB) error
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### 2. 审批引擎
|
|
131
|
-
```go
|
|
132
|
-
// 基础操作
|
|
133
|
-
approvalService.CreateInstance(...)
|
|
134
|
-
approvalService.Approve(...)
|
|
135
|
-
approvalService.Reject(...)
|
|
136
|
-
approvalService.Cancel(...)
|
|
137
|
-
|
|
138
|
-
// 流程版本控制
|
|
139
|
-
approvalService.PublishFlow(...) // draft → published
|
|
140
|
-
approvalService.DeprecateFlow(...) // published → deprecated
|
|
141
|
-
approvalService.CreateNewVersion(...) // 基于现有流程创建新版本
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
**流程状态生命周期**:`draft` → `published` → `deprecated`
|
|
145
|
-
|
|
146
|
-
### 3. 审批回调重试
|
|
147
|
-
```go
|
|
148
|
-
import approval "github.com/robsuncn/keystone/domain/approval/service"
|
|
149
|
-
|
|
150
|
-
// 带重试的回调包装
|
|
151
|
-
config := approval.RetryConfig{
|
|
152
|
-
MaxRetries: 3,
|
|
153
|
-
InitialBackoff: time.Second,
|
|
154
|
-
MaxBackoff: 30 * time.Second,
|
|
155
|
-
BackoffFactor: 2.0,
|
|
156
|
-
}
|
|
157
|
-
retryable := approval.NewRetryableCallback(callback, config)
|
|
158
|
-
|
|
159
|
-
// 异步回调执行器
|
|
160
|
-
executor := approval.NewAsyncCallbackExecutor(registry, config, 100)
|
|
161
|
-
executor.ExecuteApproved(ctx, businessType, tenantID, businessID, approverID)
|
|
162
|
-
|
|
163
|
-
// 监听结果
|
|
164
|
-
for result := range executor.Results() {
|
|
165
|
-
if !result.Success {
|
|
166
|
-
log.Error("callback failed", "error", result.Error)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### 4. Job 队列
|
|
172
|
-
```go
|
|
173
|
-
jobService.CreateJob(...)
|
|
174
|
-
jobService.GetJob(...)
|
|
175
|
-
jobService.ListJobs(...)
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### 5. 通知服务
|
|
179
|
-
```go
|
|
180
|
-
notificationService.SendNotification(...)
|
|
181
|
-
notificationService.ListNotifications(...)
|
|
182
|
-
notificationService.MarkRead(...)
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### 6. 权限中间件
|
|
186
|
-
```go
|
|
187
|
-
middleware.RequirePermission("module:resource:action")
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### 7. 存储服务
|
|
191
|
-
```go
|
|
192
|
-
storageService.Upload(...)
|
|
193
|
-
storageService.Download(...)
|
|
194
|
-
storageService.Delete(...)
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### 8. 统一分页
|
|
198
|
-
```go
|
|
199
|
-
import "github.com/robsuncn/keystone/infra/pagination"
|
|
200
|
-
|
|
201
|
-
// 解析请求参数
|
|
202
|
-
req := pagination.ParseRequest(c) // 从 Gin context 获取 page, page_size
|
|
203
|
-
|
|
204
|
-
// 方式一:使用 GORM Scope
|
|
205
|
-
db.Scopes(pagination.Scope(req)).Find(&items)
|
|
206
|
-
|
|
207
|
-
// 方式二:一步完成分页查询
|
|
208
|
-
var items []Item
|
|
209
|
-
total, err := pagination.Paginate(db.Where("tenant_id = ?", tenantID), req, &items)
|
|
210
|
-
|
|
211
|
-
// 方式三:带预加载的分页
|
|
212
|
-
total, err := pagination.PaginateWithPreload(db, req, &items, "Category", "Tags")
|
|
213
|
-
|
|
214
|
-
// 构建响应
|
|
215
|
-
resp := pagination.NewResponse(items, total, req)
|
|
216
|
-
// resp.TotalPages(), resp.HasNextPage(), resp.HasPrevPage()
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### 9. 多语言 (i18n)
|
|
220
|
-
```go
|
|
221
|
-
// 获取当前请求语言环境
|
|
222
|
-
import "github.com/robsuncn/keystone/infra/i18n"
|
|
223
|
-
|
|
224
|
-
locale := i18n.GetLocale(c) // 从请求头或参数获取
|
|
225
|
-
|
|
226
|
-
// 翻译函数
|
|
227
|
-
i18n.T(c, "module.key") // 基础翻译
|
|
228
|
-
i18n.T(c, "module.greeting", "name", "张三") // 带变量
|
|
229
|
-
i18n.Tf(c, "module.count", count) // 复数形式
|
|
230
|
-
|
|
231
|
-
// 错误消息翻译
|
|
232
|
-
return errors.New(i18n.T(c, "module.errors.notFound"))
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
**翻译文件组织**:
|
|
236
|
-
```
|
|
237
|
-
internal/modules/{module}/i18n/
|
|
238
|
-
├── i18n.go # 初始化
|
|
239
|
-
├── keys.go # 翻译键常量
|
|
240
|
-
└── locales/
|
|
241
|
-
├── zh-CN.json
|
|
242
|
-
└── en-US.json
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
**翻译键常量定义**:
|
|
246
|
-
```go
|
|
247
|
-
package i18n
|
|
248
|
-
|
|
249
|
-
const (
|
|
250
|
-
KeyItemCreated = "example.item.created"
|
|
251
|
-
KeyItemNotFound = "example.item.notFound"
|
|
252
|
-
KeyItemInvalid = "example.item.invalid"
|
|
253
|
-
)
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
**模块初始化**:
|
|
257
|
-
```go
|
|
258
|
-
func init() {
|
|
259
|
-
i18n.MustLoadModuleTranslations("example", Translations)
|
|
260
|
-
}
|
|
261
|
-
```
|