From a17fd0307dd52112bcafa5cb80098b75b7320e3d Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 25 Jun 2026 12:27:49 +0800 Subject: [PATCH] =?UTF-8?q?chore(v0.11):=20Phase=202=20=E6=B8=85=E7=90=86?= =?UTF-8?q?=20-=20=E5=88=A0=20scripts/extract-all.mjs=20(Phase=201=20?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E5=B7=B2=E5=88=A0=20data/*.json,=20=E8=BF=99?= =?UTF-8?q?=E6=98=AF=20snap=20=E8=84=9A=E6=9C=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docs/dacli/v0.11-mirror-refactor.md Phase 2 删除清单: - data/field-schemas.json ← v0.10 之前 commit 已删 - data/component-map.json ← v0.10 之前 commit 已删 - data/l2-rules.json ← v0.10 之前 commit 已删 - data/validation-rules.json ← v0.10 之前 commit 已删 - scripts/extract-web-schema.py ← v0.10 之前 commit 已删 - scripts/extract-all.mjs ← 本次删 (350 行 snapshot 提取脚本) scripts/extract-all.mjs 用途: 从 web/.../componentMap.ts/formValidate.ts/R*.vue 正则提取到 dacli/data/*.json, 然后 FieldBuilder.ts read 这些 JSON. v0.11+ 后: - dacli/src/commands/form/_buildformdata.ts 直接 import web buildFormData - dacli/data/buildformdata-contract.md 留文档 - 不再需要 snapshot 中间产物, 也不再需要 extract 脚本 package.json: 移除 'extract' script (tsx scripts/extract-all.mjs) Co-Authored-By: Claude --- package.json | 1 - scripts/extract-all.mjs | 349 ---------------------------------------- 2 files changed, 350 deletions(-) delete mode 100644 scripts/extract-all.mjs diff --git a/package.json b/package.json index 7b712c6..806a0a9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "test": "vitest run", "test:watch": "vitest", "test:e2e": "playwright test", - "extract": "tsx scripts/extract-all.mjs", "verify:baseline": "bash .claude/skills/dacli-ts/examples/baseline/all.sh", "typecheck": "tsc --noEmit" }, diff --git a/scripts/extract-all.mjs b/scripts/extract-all.mjs deleted file mode 100644 index a2dd6ff..0000000 --- a/scripts/extract-all.mjs +++ /dev/null @@ -1,349 +0,0 @@ -#!/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 -} - -// ==================== 6. report-schemas (报表设计器) ==================== -async function extractReportSchemas() { - const { parse } = await import('@vue/compiler-sfc') - const REPORT_DIRS = [ - `${WEB_ROOT}/apps/jnpf-web-apps-main/src/views/onlineDev/report`, - `${WEB_ROOT}/apps/jnpf-web-apps-main/src/views/onlineDev/dataReport`, - `${WEB_ROOT}/apps/jnpf-web-apps-main/src/views/common/dynamicReport`, - ] - const schemas = { version: 'v0.8-scaffold', components: [], categories: [], apiRef: '/api/extend/ReportManage' } - for (const dir of REPORT_DIRS) { - if (!existsSync(dir)) continue - const FormPath = resolve(dir, 'Form.vue') - if (!existsSync(FormPath)) continue - const src = readFileSync(FormPath, 'utf-8') - const { descriptor } = parse(src, { filename: FormPath }) - const tmpl = descriptor.template?.content || '' - const script = descriptor.scriptSetup?.content || descriptor.script?.content || '' - const fields = [...new Set( - [...tmpl.matchAll(/activeData\.([a-zA-Z_][\w.]*)/g)].map(m => m[1]) - )].sort().filter(f => !f.includes('.splice') && !f.includes('.push')) - const calls = [...script.matchAll(/api\.(get|post|put|del)\s*\(\s*['"]([^'"]+)['"]/g)].map(m => m[2]) - schemas.components.push({ dir: dir.split('/views/').pop(), fields, apiCalls: [...new Set(calls)] }) - } - // 报表分类 (1=简易 2=专业) - schemas.categories = [{ id: 1, name: '简易报表' }, { id: 2, name: '专业报表' }] - writeFileSync(resolve(OUT_DIR, 'report-schemas.json'), JSON.stringify(schemas, null, 2)) - return schemas.components.length -} - -// ==================== 7. portal-schemas (门户设计器) ==================== -async function extractPortalSchemas() { - const { parse } = await import('@vue/compiler-sfc') - const PORTAL_DIRS = [ - `${WEB_ROOT}/apps/jnpf-web-apps-main/src/views/onlineDev/visualPortal`, - `${WEB_ROOT}/apps/jnpf-web-apps-main/src/views/common/dynamicPortal`, - ] - const schemas = { version: 'v0.8-scaffold', components: [], categories: [], apiRef: '/api/visualdev/Portal' } - for (const dir of PORTAL_DIRS) { - if (!existsSync(dir)) continue - const FormPath = resolve(dir, 'Form.vue') - if (!existsSync(FormPath)) continue - const src = readFileSync(FormPath, 'utf-8') - const { descriptor } = parse(src, { filename: FormPath }) - const tmpl = descriptor.template?.content || '' - const script = descriptor.scriptSetup?.content || descriptor.script?.content || '' - const fields = [...new Set( - [...tmpl.matchAll(/activeData\.([a-zA-Z_][\w.]*)/g)].map(m => m[1]) - )].sort().filter(f => !f.includes('.splice') && !f.includes('.push')) - const calls = [...script.matchAll(/api\.(get|post|put|del)\s*\(\s*['"]([^'"]+)['"]/g)].map(m => m[2]) - schemas.components.push({ dir: dir.split('/views/').pop(), fields, apiCalls: [...new Set(calls)] }) - } - // 门户分类 (1=经典 2=全屏) - schemas.categories = [{ id: 1, name: '经典门户' }, { id: 2, name: '全屏门户' }] - writeFileSync(resolve(OUT_DIR, 'portal-schemas.json'), JSON.stringify(schemas, null, 2)) - return schemas.components.length -} - -// ==================== 8. bigdata-schemas (大屏设计器) ==================== -async function extractBigdataSchemas() { - const { parse } = await import('@vue/compiler-sfc') - const BIG_DIR = `${WEB_ROOT}/apps/jnpf-web-apps-main/src/views/extend/bigData` - const schemas = { version: 'v0.8-scaffold', components: [], categories: [], apiRef: '/api/extend/BigData' } - if (existsSync(BIG_DIR)) { - const FormPath = resolve(BIG_DIR, 'index.vue') - if (existsSync(FormPath)) { - const src = readFileSync(FormPath, 'utf-8') - const { descriptor } = parse(src, { filename: FormPath }) - const tmpl = descriptor.template?.content || '' - const script = descriptor.scriptSetup?.content || descriptor.script?.content || '' - const fields = [...new Set( - [...tmpl.matchAll(/activeData\.([a-zA-Z_][\w.]*)/g)].map(m => m[1]) - )].sort().filter(f => !f.includes('.splice') && !f.includes('.push')) - const calls = [...script.matchAll(/api\.(get|post|put|del)\s*\(\s*['"]([^'"]+)['"]/g)].map(m => m[2]) - schemas.components.push({ dir: 'bigData', fields, apiCalls: [...new Set(calls)] }) - } - } - // 大屏分类 (1=数据大屏 2=仪表盘) - schemas.categories = [{ id: 1, name: '数据大屏' }, { id: 2, name: '仪表盘' }] - writeFileSync(resolve(OUT_DIR, 'bigdata-schemas.json'), JSON.stringify(schemas, null, 2)) - return schemas.components.length -} - -// ==================== 9. datasource-drivers (静态) ==================== -// 数据源 driver 列表, 来自 JNPF `application.yml` 默认配置 + jnpf-base 数据源 -// (这是 v0.8-scaffold: 静态清单, 后续接 web DbLinkForm.vue 提取动态 driver 列表) -function extractDatasourceDrivers() { - const drivers = [ - { id: 'MySQL', name: 'MySQL', defaultPort: 3306, jdbc: 'jdbc:mysql://' }, - { id: 'SQLServer', name: 'SQL Server', defaultPort: 1433, jdbc: 'jdbc:sqlserver://' }, - { id: 'Oracle', name: 'Oracle', defaultPort: 1521, jdbc: 'jdbc:oracle://' }, - { id: 'PostgreSQL', name: 'PostgreSQL', defaultPort: 5432, jdbc: 'jdbc:postgresql://' }, - { id: 'DM', name: '达梦 DM', defaultPort: 5236, jdbc: 'jdbc:dm://' }, - { id: 'Kingbase', name: '人大金仓 Kingbase', defaultPort: 54321, jdbc: 'jdbc:kingbase8://' }, - { id: 'HighGo', name: '高斯 DB HighGo', defaultPort: 5866, jdbc: 'jdbc:highgo://' }, - { id: 'SQLite', name: 'SQLite', defaultPort: 0, jdbc: 'jdbc:sqlite:' }, - ] - const out = { - version: 'v0.8-scaffold', - note: '静态 driver 列表, 后续接 web DbLinkForm.vue 提取动态', - apiRef: '/api/system/DataSource', - drivers, - } - writeFileSync(resolve(OUT_DIR, 'datasource-drivers.json'), JSON.stringify(out, null, 2)) - return drivers.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}`) - } - - // v0.8 W7-D4 新增 4 extractor - try { - const n6 = await extractReportSchemas() - console.log(` ✓ report-schemas.json: ${n6} 个报表组件`) - } catch (e) { - console.log(` ✗ report-schemas: ${e.message}`) - } - - try { - const n7 = await extractPortalSchemas() - console.log(` ✓ portal-schemas.json: ${n7} 个门户组件`) - } catch (e) { - console.log(` ✗ portal-schemas: ${e.message}`) - } - - try { - const n8 = await extractBigdataSchemas() - console.log(` ✓ bigdata-schemas.json: ${n8} 个大屏组件`) - } catch (e) { - console.log(` ✗ bigdata-schemas: ${e.message}`) - } - - try { - const n9 = extractDatasourceDrivers() - console.log(` ✓ datasource-drivers.json: ${n9} 个 driver`) - } catch (e) { - console.log(` ✗ datasource-drivers: ${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) })