参考 boot/ 仓库结构初始化, 同步到 gitea:3000/ssw/dacli (private). 包括: - src/ 8 父命令 (form/menu/dm/dict/di/apis/doc/workflow + login/status) + core (client/crypto/help/log/types/config) - src/schema/ FieldBuilder (从 JNPF web 源码提取, 避免 53 个手写 builder) - tests/ vitest 单元 + playwright E2E (含 workSystem/developSystem baseline regression) - scripts/ extract-all.mjs (从 jnpf-web 源码生成 schema) + seed-tds-baseline.ts - doc/ architecture/plan/api/extractors/baseline/RESUME/help-system + v0.6/v0.7 changelog - .claude/skills/dacli-ts/ Claude 集成 skill (SKILL.md + 5 references + 7 examples + 3 baseline) - CLAUDE.md (项目说明) + README.md + prompt.md (开发任务说明书) - 配置文件: package.json/lock, tsconfig, vitest.config, playwright.config
8.8 KiB
8.8 KiB
extractors.md — web 源码提取工具说明
位置:
$ccWorkDir/dacli/doc/extractors.md目标: 5 个 extractor 工具, 从 web 源码自动生成 data/*.json
1. 概览
| Extractor | 输入 | 输出 | 大小 | 跑时 |
|---|---|---|---|---|
component-map.ts |
web/.../componentMap.ts |
data/component-map.json |
60+ jnpfKey | < 1s |
fields.ts |
web/.../rightComponents/R*.vue |
data/field-schemas.json |
39 控件 | < 5s |
l1-rules.ts |
web/.../formValidate.ts |
data/validation-rules.json |
14 正则 | < 1s |
l2-rules.ts |
web/.../Form.vue 多个 |
data/l2-rules.json |
30+ 规则 | < 5s |
flow.ts |
web/.../FlowProcess/index.vue |
data/flow-nodes.json |
25+ 节点 | < 5s |
一键跑全部:
node scripts/extract-all.mjs
2. component-map.ts 提取
输入: web/apps/jnpf-web-apps-main/src/components/FormGenerator/src/helper/componentMap.ts
提取内容:
- jnpfKey → tag (e.g.
input→JnpfInput) - 控件元数据
输出 (data/component-map.json):
{
"input": "JnpfInput",
"textarea": "JnpfTextarea",
"select": "JnpfSelect",
...
}
实现:
// src/extractors/component-map.ts
import { readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
const SRC = 'web/apps/jnpf-web-apps-main/src/components/FormGenerator/src/helper/componentMap.ts'
const OUT = 'src/data/component-map.json'
export function extractComponentMap() {
const src = readFileSync(resolve(SRC), 'utf-8')
const items = [...src.matchAll(/jnpfKey:\s*['"](\w+)['"][\s\S]*?tag:\s*['"]([^'"]+)['"]/g)]
const map: Record<string, string> = {}
for (const m of items) map[m[1]] = m[2]
writeFileSync(resolve(OUT), JSON.stringify(map, null, 2))
return Object.keys(map).length
}
3. fields.ts 提取 (核心)
输入: web/.../rightComponents/R*.vue (39 个)
提取: Rxxx.vue template 里所有 activeData.<path> 形式, 得到控件字段集
输出 (data/field-schemas.json):
{
"input": [
"__config__.defaultValue", "__config__.noShow", "__config__.required",
"addonAfter", "addonBefore", "clearable", "disabled", "maxlength",
"prefixIcon", "readonly", "showCount", "showPassword", "suffixIcon",
"useMask", "useScan"
],
"select": [
"__config__.defaultValue", "clearable", "filterable", "multiple",
"options", "props"
],
...
}
实现:
// src/extractors/fields.ts
import { parse as parseSFC } from '@vue/compiler-sfc'
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
const R_DIR = 'web/.../rightComponents'
const COMP_MAP = 'web/.../componentMap.ts'
const OUT = 'src/data/field-schemas.json'
export function extractFields() {
// 1. 读 componentMap (jnpfKey → tag)
const cmSrc = readFileSync(COMP_MAP, 'utf-8')
const jnpfKeyToTag: Record<string, string> = {}
for (const m of cmSrc.matchAll(/jnpfKey:\s*['"](\w+)['"][\s\S]*?tag:\s*['"]([^'"]+)['"]/g)) {
jnpfKeyToTag[m[1]] = m[2]
}
// 2. 对每个 jnpfKey 找对应 R<Cap>.vue
const schemas: Record<string, string[]> = {}
for (const key of Object.keys(jnpfKeyToTag)) {
const pascal = key.charAt(0).toUpperCase() + key.slice(1)
const f = resolve(R_DIR, `R${pascal}.vue`)
try {
const src = readFileSync(f, 'utf-8')
const { descriptor } = parseSFC(src, { filename: `R${pascal}.vue` })
const tmpl = descriptor.template?.content
if (!tmpl) continue
// 提所有 activeData.<path>
const fields = [...new Set(
[...tmpl.matchAll(/activeData\.([a-zA-Z_][\w.]*)/g)].map(m => m[1])
)].sort()
schemas[key] = fields
} catch { /* 文件不存在, 跳过 */ }
}
writeFileSync(resolve(OUT), JSON.stringify(schemas, null, 2))
return Object.keys(schemas).length
}
覆盖率:
- 60+ jnpfKey 中能找 39 个 R 文件
- 14 个 R 文件缺失 (Jnpf/ 目录下的子组件)
- input 控件 19 字段 (vs dacli Java 43 字段, 44% 覆盖率)
- 整体 60-80% 字段覆盖率, 剩 20-40% 用 baseline 补
4. l1-rules.ts 提取
输入: web/packages/jnpf/utils/src/helpers/formValidate.ts
提取: 14 条 L1 正则 (enCode, fullName, field, chinese, bigInt, ...)
输出 (data/validation-rules.json):
{
"enCode": {
"msg": "只能输入英文、数字和小数点且小数点不能放在首尾",
"rule": "^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\\.)*[a-z0-9]))$/i"
},
"fullName": {
"msg": "名称不能含有特殊符号",
"rule": "^([一-龥a-z0-9])+$/i"
},
...
}
实现:
// src/extractors/l1-rules.ts
import { readFileSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
const SRC = 'web/packages/jnpf/utils/src/helpers/formValidate.ts'
const OUT = 'src/data/validation-rules.json'
export function extractL1Rules() {
const src = readFileSync(resolve(SRC), 'utf-8')
const match = src.match(/const regularList\s*=\s*\{([\s\S]*?)\n\}/)
if (!match) throw new Error('regularList not found')
const rules: Record<string, { msg: string; rule: string }> = {}
// 提每条 key 的 msg + rule
for (const m of match[1].matchAll(/(\w+):\s*\{[\s\S]*?msg:\s*'([^']+)'[\s\S]*?rule:\s*(\/[^\/]+\/[a-z]*)[\s\S]*?\}/g)) {
rules[m[1]] = { msg: m[2], rule: m[3] }
}
writeFileSync(resolve(OUT), JSON.stringify(rules, null, 2))
return Object.keys(rules).length
}
5. l2-rules.ts 提取
输入: web/.../views/{module}/Form.vue 多个
提取: createMessage.error/warning('msg') + 上下文
输出 (data/l2-rules.json):
{
"di": [
{ "line": 472, "msg": "请输入静态数据", "condition": "type == 2", "dacli": "--static-data" },
{ "line": 522, "msg": "请输入SQL查询语句", "condition": "type == 1, activeStep == 1", "dacli": "--sql-query" }
],
"dm": [...],
"dict": [...],
"workflow": [...]
}
实现:
// src/extractors/l2-rules.ts
import { parse as parseSFC } from '@vue/compiler-sfc'
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
export function extractL2Rules() {
const rules: Record<string, any[]> = { di: [], dm: [], dict: [], workflow: [] }
// 扫所有 Form.vue
const viewsDir = 'web/apps/jnpf-web-apps-main/src/views'
const forms = findAllFiles(viewsDir, /Form\.vue$/)
for (const f of forms) {
const module = f.includes('/dataInterface/') ? 'di'
: f.includes('/dataModel/') ? 'dm'
: f.includes('/dictionary/') ? 'dict'
: f.includes('/flowEngine/') ? 'workflow'
: null
if (!module) continue
const src = readFileSync(f, 'utf-8')
const { descriptor } = parseSFC(src)
const script = descriptor.scriptSetup?.content || descriptor.script?.content || ''
// 提 createMessage.error/warning
for (const m of script.matchAll(/createMessage\.(error|warning)\s*\(\s*['"]([^'"]+)['"]/g)) {
rules[module].push({
level: m[1],
msg: m[2],
line: getLineNumber(script, m.index!),
source: f.replace(/^.*\/web\//, 'web/'),
})
}
}
writeFileSync(resolve(OUT), JSON.stringify(rules, null, 2))
return Object.values(rules).reduce((a, b) => a + b.length, 0)
}
6. flow.ts 提取
输入: web/.../components/FlowProcess/src/index.vue
提取: setErrorList(msg, id, title) 调用 + 节点 type
输出 (data/flow-nodes.json):
{
"addData": { "formId": "必填", "msg": "请选择目标表单" },
"updateData": { "formId": "必填", "ruleList": "必填, 至少 1 条", "msg": "请设置更新条件" },
"typeDecision": { "decisionOptions": "必填", "msg": "节点未完善" },
...
}
7. 一键提取 (scripts/extract-all.mjs)
#!/usr/bin/env node
// scripts/extract-all.mjs
import { extractComponentMap } from '../src/extractors/component-map.ts'
import { extractFields } from '../src/extractors/fields.ts'
import { extractL1Rules } from '../src/extractors/l1-rules.ts'
import { extractL2Rules } from '../src/extractors/l2-rules.ts'
import { extractFlow } from '../src/extractors/flow.ts'
console.log('▶ extractComponentMap:', extractComponentMap(), 'jnpfKey')
console.log('▶ extractFields: ', extractFields(), '控件')
console.log('▶ extractL1Rules: ', extractL1Rules(), '条')
console.log('▶ extractL2Rules: ', extractL2Rules(), '条')
console.log('▶ extractFlow: ', extractFlow(), '节点')
console.log('✓ 全部提取完成')
8. 何时重跑
| 触发 | 行为 |
|---|---|
| JNPF 升级 | 必跑, 5 分钟看 web 改了哪些 |
| 新增 Rxxx.vue | 跑 extract 拿新控件 schema |
| 修改 formValidate | 跑 extract 拿新规则 |
| 改 componentMap | 跑 extract 拿新映射 |
9. 反向链接
- architecture.md — 设计
- plan.md — 6 周路线
- api.md — API
- baseline.md — 0 差错
- help-system.md — 帮助体系