init: TS 版 dacli v0.7 baseline (8 父命令/26+ 子命令, 0.4MB, .claude/skills/dacli-ts)
参考 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
This commit is contained in:
commit
c98ad4f425
93 files changed
+12718
No files matched your search
@@ -0,0 +1,214 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* scripts/extract-all.mjs
|
||||
*
|
||||
* 一键从 web 源码提取所有资产到 src/data/*.json
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/extract-all.mjs
|
||||
*
|
||||
* JNPF 升级时重跑:
|
||||
* 1. cd $ccWorkDir/dacli
|
||||
* 2. node scripts/extract-all.mjs
|
||||
* 3. 看 git diff data/ 知道 web 改了哪些
|
||||
* 4. 跑 baseline 验证 dacli 还兼容
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync, existsSync } from 'node:fs'
|
||||
import { resolve, dirname } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const ROOT = resolve(__dirname, '..')
|
||||
|
||||
// web 源码绝对路径
|
||||
const WEB_ROOT = process.env.WEB_ROOT || '/Users/xs/Desktop/workspace/web'
|
||||
const COMP_MAP = `${WEB_ROOT}/apps/jnpf-web-apps-main/src/components/FormGenerator/src/helper/componentMap.ts`
|
||||
const FORM_VALIDATE = `${WEB_ROOT}/packages/jnpf/utils/src/helpers/formValidate.ts`
|
||||
const R_DIR = `${WEB_ROOT}/apps/jnpf-web-apps-main/src/components/FormGenerator/src/rightComponents`
|
||||
|
||||
// 输出
|
||||
const OUT_DIR = resolve(ROOT, 'src/data')
|
||||
|
||||
// ==================== 1. componentMap ====================
|
||||
function extractComponentMap() {
|
||||
const src = readFileSync(COMP_MAP, 'utf-8')
|
||||
const items = [...src.matchAll(/jnpfKey:\s*['"](\w+)['"][\s\S]*?tag:\s*['"]([^'"]+)['"]/g)]
|
||||
const map = {}
|
||||
for (const m of items) map[m[1]] = m[2]
|
||||
writeFileSync(resolve(OUT_DIR, 'component-map.json'), JSON.stringify(map, null, 2))
|
||||
return items.length
|
||||
}
|
||||
|
||||
// ==================== 2. fields (Rxxx.vue) ====================
|
||||
// 注: 需要 @vue/compiler-sfc, 这里用 require 加载
|
||||
async function extractFields() {
|
||||
const { parse } = await import('@vue/compiler-sfc')
|
||||
const { readdirSync } = await import('node:fs')
|
||||
|
||||
// 读 componentMap
|
||||
const cmSrc = readFileSync(COMP_MAP, 'utf-8')
|
||||
const jnpfKeyToTag = {}
|
||||
for (const m of cmSrc.matchAll(/jnpfKey:\s*['"](\w+)['"][\s\S]*?tag:\s*['"]([^'"]+)['"]/g)) {
|
||||
jnpfKeyToTag[m[1]] = m[2]
|
||||
}
|
||||
|
||||
const schemas = {}
|
||||
for (const key of Object.keys(jnpfKeyToTag)) {
|
||||
const pascal = key.charAt(0).toUpperCase() + key.slice(1)
|
||||
const f = resolve(R_DIR, `R${pascal}.vue`)
|
||||
if (!existsSync(f)) continue
|
||||
const src = readFileSync(f, 'utf-8')
|
||||
const { descriptor } = parse(src, { filename: `R${pascal}.vue` })
|
||||
const tmpl = descriptor.template?.content
|
||||
if (!tmpl) continue
|
||||
const fields = [...new Set(
|
||||
[...tmpl.matchAll(/activeData\.([a-zA-Z_][\w.]*)/g)].map(m => m[1])
|
||||
)].sort()
|
||||
// 过滤掉方法调用 (e.g. __config__.regList.splice 不是字段)
|
||||
const cleanFields = fields.filter(f => !f.includes('.splice') && !f.includes('.push'))
|
||||
schemas[key] = cleanFields
|
||||
}
|
||||
|
||||
writeFileSync(resolve(OUT_DIR, 'field-schemas.json'), JSON.stringify(schemas, null, 2))
|
||||
return Object.keys(schemas).length
|
||||
}
|
||||
|
||||
// ==================== 3. l1-rules ====================
|
||||
function extractL1Rules() {
|
||||
const src = readFileSync(FORM_VALIDATE, 'utf-8')
|
||||
const match = src.match(/const regularList\s*=\s*\{([\s\S]*?)\n\}/)
|
||||
if (!match) throw new Error('regularList not found in formValidate.ts')
|
||||
|
||||
const rules = {}
|
||||
// 提每条 key 的 msg + rule
|
||||
for (const m of match[1].matchAll(/(\w+):\s*\{[^{}]*?msg:\s*['"]([^'"]+)['"][^{}]*?rule:\s*(\/[^\/]+\/[a-z]*)/g)) {
|
||||
rules[m[1]] = { msg: m[2], rule: m[3] }
|
||||
}
|
||||
writeFileSync(resolve(OUT_DIR, 'validation-rules.json'), JSON.stringify(rules, null, 2))
|
||||
return Object.keys(rules).length
|
||||
}
|
||||
|
||||
// ==================== 4. l2-rules (Form.vue) ====================
|
||||
async function extractL2Rules() {
|
||||
const { parse } = await import('@vue/compiler-sfc')
|
||||
const { readdirSync, statSync } = await import('node:fs')
|
||||
const rules = { di: [], dm: [], dict: [], workflow: [], menu: [], role: [], user: [] }
|
||||
|
||||
function walk(dir) {
|
||||
if (!existsSync(dir)) return
|
||||
for (const f of readdirSync(dir)) {
|
||||
const p = resolve(dir, f)
|
||||
const s = statSync(p)
|
||||
if (s.isDirectory()) walk(p)
|
||||
else if (f.endsWith('.vue') && f === 'Form.vue') {
|
||||
parseForm(p, rules)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseForm(file, rules) {
|
||||
const module = file.includes('/dataInterface/') ? 'di'
|
||||
: file.includes('/dataModel/') ? 'dm'
|
||||
: file.includes('/dictionary/') ? 'dict'
|
||||
: file.includes('/flowEngine/') ? 'workflow'
|
||||
: file.includes('/menu/') ? 'menu'
|
||||
: file.includes('/role/') ? 'role'
|
||||
: file.includes('/user/') ? 'user'
|
||||
: null
|
||||
if (!module || !rules[module]) return
|
||||
|
||||
const src = readFileSync(file, 'utf-8')
|
||||
const { descriptor } = parse(src, { filename: file })
|
||||
const script = descriptor.scriptSetup?.content || descriptor.script?.content || ''
|
||||
|
||||
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: file.replace(/^.*\/web\//, 'web/'),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getLineNumber(text, index) {
|
||||
return text.slice(0, index).split('\n').length
|
||||
}
|
||||
|
||||
walk(`${WEB_ROOT}/apps/jnpf-web-apps-main/src/views`)
|
||||
|
||||
writeFileSync(resolve(OUT_DIR, 'l2-rules.json'), JSON.stringify(rules, null, 2))
|
||||
return Object.values(rules).reduce((a, b) => a + b.length, 0)
|
||||
}
|
||||
|
||||
// ==================== 5. flow nodes ====================
|
||||
async function extractFlow() {
|
||||
const { parse } = await import('@vue/compiler-sfc')
|
||||
const FLOW_FILE = `${WEB_ROOT}/apps/jnpf-web-apps-main/src/components/FlowProcess/src/index.vue`
|
||||
if (!existsSync(FLOW_FILE)) {
|
||||
console.log(' (FlowProcess/src/index.vue 不存在, 跳过)')
|
||||
return 0
|
||||
}
|
||||
|
||||
const src = readFileSync(FLOW_FILE, 'utf-8')
|
||||
const { descriptor } = parse(src, { filename: FLOW_FILE })
|
||||
const script = descriptor.scriptSetup?.content || descriptor.script?.content || ''
|
||||
|
||||
const nodes = {}
|
||||
for (const m of script.matchAll(/setErrorList\s*\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]*)['"]\s*,\s*['"]([^'"]*)['"]/g)) {
|
||||
const [_, msg, key, title] = m
|
||||
if (title && !nodes[title]) nodes[title] = { msg, key }
|
||||
}
|
||||
|
||||
writeFileSync(resolve(OUT_DIR, 'flow-nodes.json'), JSON.stringify(nodes, null, 2))
|
||||
return Object.keys(nodes).length
|
||||
}
|
||||
|
||||
// ==================== main ====================
|
||||
async function main() {
|
||||
console.log('▶ 一键提取 web 源码 → src/data/*.json\n')
|
||||
|
||||
try {
|
||||
const n1 = extractComponentMap()
|
||||
console.log(` ✓ component-map.json: ${n1} 个 jnpfKey → tag`)
|
||||
} catch (e) {
|
||||
console.log(` ✗ component-map: ${e.message}`)
|
||||
}
|
||||
|
||||
try {
|
||||
const n2 = await extractFields()
|
||||
console.log(` ✓ field-schemas.json: ${n2} 个控件`)
|
||||
} catch (e) {
|
||||
console.log(` ✗ field-schemas: ${e.message}`)
|
||||
}
|
||||
|
||||
try {
|
||||
const n3 = extractL1Rules()
|
||||
console.log(` ✓ validation-rules.json: ${n3} 条 L1 正则`)
|
||||
} catch (e) {
|
||||
console.log(` ✗ validation-rules: ${e.message}`)
|
||||
}
|
||||
|
||||
try {
|
||||
const n4 = await extractL2Rules()
|
||||
console.log(` ✓ l2-rules.json: ${n4} 条 L2 错误消息`)
|
||||
} catch (e) {
|
||||
console.log(` ✗ l2-rules: ${e.message}`)
|
||||
}
|
||||
|
||||
try {
|
||||
const n5 = await extractFlow()
|
||||
console.log(` ✓ flow-nodes.json: ${n5} 个工作流节点`)
|
||||
} catch (e) {
|
||||
console.log(` ✗ flow-nodes: ${e.message}`)
|
||||
}
|
||||
|
||||
console.log('\n✓ 全部提取完成')
|
||||
console.log(' 下一步:')
|
||||
console.log(' 1. 看 src/data/ 下的 JSON')
|
||||
console.log(' 2. 跑 baseline: bash examples/baseline/all.sh --skip-visual')
|
||||
console.log(' 3. 全通: npx playwright test')
|
||||
}
|
||||
|
||||
main().catch(e => { console.error(e); process.exit(1) })
|
||||
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env -S npx tsx
|
||||
/**
|
||||
* scripts/seed-tds-baseline.ts
|
||||
*
|
||||
* 把 workSystem 5-7 张代表性 form export 到 /tmp/baseline/, 再 import 到 tds.
|
||||
* 输出 /tmp/baseline-mapping.json (origId → cloneId) 供 baseline spec 用.
|
||||
*
|
||||
* 用户指引: 测试在 tds 做, 数据从官方示例复制 — 官方示例只读不动.
|
||||
*
|
||||
* 跑法:
|
||||
* npx tsx scripts/seed-tds-baseline.ts
|
||||
*
|
||||
* 选择标准 (5 张代表性, 5 维度覆盖):
|
||||
* - yuangongpx (type=1, 无 flow) 单表
|
||||
* - ruzhishenq (type=1, 无 flow) 单表 (HR)
|
||||
* - renewal (type=1, 无 flow) 单表 (合同)
|
||||
* - leaveApply (type=2, flow=1) 工作流表单 (经典)
|
||||
* - crmOrder (type=2, flow=1) 工作流表单 (订单)
|
||||
*/
|
||||
import { execSync } from 'node:child_process'
|
||||
import { mkdirSync, writeFileSync, existsSync } from 'node:fs'
|
||||
|
||||
const SELECTED = [
|
||||
{ enCode: 'yuangongpx', fullName: '员工培训' },
|
||||
{ enCode: 'ruzhishenq', fullName: '入职申请' },
|
||||
{ enCode: 'renewal', fullName: '劳动合同续签' },
|
||||
{ enCode: 'leaveApply', fullName: '请假申请' },
|
||||
{ enCode: 'crmOrder', fullName: '订单示例' },
|
||||
] as const
|
||||
|
||||
const EXPORT_DIR = '/tmp/baseline-orig'
|
||||
const MAPPING_FILE = '/tmp/baseline-mapping.json'
|
||||
const CLONE_SUFFIX = '_ws' // workSystem 来源标记
|
||||
|
||||
interface Form {
|
||||
id: string
|
||||
enCode: string
|
||||
fullName: string
|
||||
type: number
|
||||
enableFlow: number | null
|
||||
}
|
||||
interface Mapping {
|
||||
origAppCode: string
|
||||
origId: string
|
||||
origEnCode: string
|
||||
origFullName: string
|
||||
cloneAppCode: string
|
||||
cloneId: string
|
||||
cloneEnCode: string
|
||||
cloneFullName: string
|
||||
imported: string
|
||||
}
|
||||
|
||||
function dacli(args: string, opts: { silent?: boolean } = {}): string {
|
||||
if (!opts.silent) console.log(` $ dacli ${args}`)
|
||||
return execSync(`npx tsx src/cli.ts ${args}`, { encoding: 'utf-8' })
|
||||
}
|
||||
|
||||
async function main() {
|
||||
mkdirSync(EXPORT_DIR, { recursive: true })
|
||||
|
||||
// 1. 切到 workSystem, 拿 5 张 form 的 id
|
||||
console.log('▶ 切到 workSystem 拿 id...')
|
||||
dacli(`switch-app --appCode=workSystem`, { silent: true })
|
||||
const listRaw = dacli(`form list --limit=200 --json`, { silent: true })
|
||||
const all = (JSON.parse(listRaw) as { list: Form[] }).list
|
||||
const targets = SELECTED.map((s) => {
|
||||
const f = all.find((x) => x.enCode === s.enCode)
|
||||
if (!f) throw new Error(`workSystem 找不到 ${s.enCode}, list 总数=${all.length}`)
|
||||
return f
|
||||
})
|
||||
console.log(` ✓ 锁定 ${targets.length} 张 workSystem form`)
|
||||
|
||||
// 2. export 每张
|
||||
console.log('▶ export workSystem 5 张 → /tmp/baseline-orig/')
|
||||
for (const f of targets) {
|
||||
const out = `${EXPORT_DIR}/${f.enCode}.json`
|
||||
dacli(`form export ${f.id} --out=${out}`, { silent: true })
|
||||
console.log(` ✓ ${f.enCode} (${f.fullName})`)
|
||||
}
|
||||
|
||||
// 3. 切到 tds, 清掉旧 _ws 克隆
|
||||
console.log('▶ 切到 tds, 清理旧 _ws 克隆')
|
||||
dacli(`switch-app --appCode=tds`, { silent: true })
|
||||
const tdsRaw = dacli(`form list --limit=200 --json`, { silent: true })
|
||||
const tdsAll = (JSON.parse(tdsRaw) as { list: Form[] }).list
|
||||
for (const f of tdsAll.filter((x) => x.enCode.endsWith(CLONE_SUFFIX))) {
|
||||
try {
|
||||
dacli(`form delete ${f.id} --yes`, { silent: true })
|
||||
console.log(` ✗ 删旧 ${f.enCode}`)
|
||||
} catch (e) {
|
||||
console.log(` ! 删 ${f.enCode} 失败 (忽略): ${(e as Error).message.slice(0, 80)}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 4. import 每张 → tds
|
||||
console.log('▶ import 5 张 → tds')
|
||||
const mapping: Mapping[] = []
|
||||
for (const f of targets) {
|
||||
const file = `${EXPORT_DIR}/${f.enCode}.json`
|
||||
const cloneEnCode = `${f.enCode}${CLONE_SUFFIX}`
|
||||
const cloneFullName = `${f.fullName}(ws克隆)`
|
||||
try {
|
||||
const out = dacli(
|
||||
`form import ${file} --enCode=${cloneEnCode} --fullName="${cloneFullName}"${f.enableFlow === 1 ? '' : ' --release'}`,
|
||||
{ silent: true }
|
||||
)
|
||||
// import 输出 "✓ 导入成功 id=XXX enCode=YYY"
|
||||
const m = out.match(/id=(\S+)\s+enCode=/)
|
||||
const cloneId = m?.[1] && m[1] !== '(unknown)' ? m[1] : ''
|
||||
if (!cloneId) {
|
||||
console.log(` ! ${f.enCode} import 返回未拿到 id: ${out.trim().slice(0, 150)}`)
|
||||
continue
|
||||
}
|
||||
mapping.push({
|
||||
origAppCode: 'workSystem',
|
||||
origId: f.id,
|
||||
origEnCode: f.enCode,
|
||||
origFullName: f.fullName,
|
||||
cloneAppCode: 'tds',
|
||||
cloneId,
|
||||
cloneEnCode,
|
||||
cloneFullName,
|
||||
imported: new Date().toISOString(),
|
||||
})
|
||||
console.log(` ✓ ${f.enCode} → ${cloneEnCode} (id=${cloneId})`)
|
||||
} catch (e) {
|
||||
console.log(` ✗ ${f.enCode} import 失败: ${(e as Error).message.slice(0, 200)}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 写 mapping
|
||||
writeFileSync(MAPPING_FILE, JSON.stringify(mapping, null, 2))
|
||||
console.log(`\n✓ ${mapping.length}/${targets.length} 张克隆成功`)
|
||||
console.log(`✓ mapping 写到 ${MAPPING_FILE}`)
|
||||
console.log('\n后续: npx playwright test tests/e2e/baseline/workSystem/ --project=chromium')
|
||||
}
|
||||
|
||||
void main().catch((e) => {
|
||||
console.error('FAIL:', e.message)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in new issue
Block a user