-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_refs.js
More file actions
40 lines (36 loc) · 1.5 KB
/
Copy pathcheck_refs.js
File metadata and controls
40 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 验证 index.js 引用一致性
const fs = require('fs');
// 读取 index.js 和所有组件文件,提取 const XXX = 导出的变量名
const idx = fs.readFileSync('e:/WEB5600/sqlite-web/webapp/static/index.js', 'utf8');
const compDir = 'e:/WEB5600/sqlite-web/webapp/static/components';
const compFiles = ['login-page.js','data-browse.js','ddl-view.js','design-table.js','query-panel.js','db-info.js'];
const defined = {};
for (const f of compFiles) {
const c = fs.readFileSync(compDir + '/' + f, 'utf8');
// 匹配 "const XXX = {"
const m = c.match(/const\s+(\w+)\s*=\s*\{/);
if (m) defined[f] = m[1];
}
console.log('=== 组件定义 ===');
for (const f in defined) console.log(' ' + f + ' -> ' + defined[f]);
// 提取 index.js 中 components 块
const m = idx.match(/components:\s*\{([\s\S]*?)\}/);
if (!m) { console.log('FAIL: 找不到 components 块'); process.exit(1); }
const block = m[1];
const refs = [...block.matchAll(/^\s*(\w+)\s*[,}]/gm)].map(x => x[1]);
console.log('=== components 注册引用 ===');
for (const r of refs) {
const matched = Object.values(defined).includes(r);
console.log(' ' + r + (matched ? ' [OK]' : ' [未定义!]'));
}
// 提取 computed 中引用的组件
const cpm = idx.match(/computed:\s*\{([\s\S]*?)\n\s*\},/);
if (cpm) {
const cpBlock = cpm[1];
console.log('=== computed 中组件引用 ===');
for (const v of Object.values(defined)) {
if (cpBlock.includes('return ' + v) || cpBlock.includes(' ' + v + ' ')) {
console.log(' ' + v + ' [OK]');
}
}
}