Commit 15e8ac01 by Lin Wang

feat: diff the nav info

parent 0f005353
......@@ -23,6 +23,9 @@ const baselineFile = `${diffBaselineId}_extractNav.json`;
const baselinePath = join(srcDir, baselineFile);
const baselineData = JSON.parse(readFileSync(baselinePath, 'utf-8'));
// Fields to ignore during diff
const ignoreFields = ['category'];
// Get all nav files excluding baseline
const allFiles = readdirSync(srcDir).filter(f => f.endsWith('_extractNav.json') && f !== baselineFile);
......@@ -32,11 +35,50 @@ allFiles.forEach(file => {
const otherData = JSON.parse(readFileSync(otherPath, 'utf-8'));
// Compute differences
const changes = diff(baselineData, otherData) || [];
const changes = diff(baselineData, otherData, (path, key) => ignoreFields.includes(key)) || [];
// Convert to semantic format
const semantic = changes.map(change => {
const map: Record<string, string> = { E: '修改', N: '新增', D: '删除', A: '数组类型的变更' };
const type = map[change.kind] || change.kind;
const pathStr = (change.path || []).filter(seg => typeof seg !== 'number').join('.');
let oldV: any, newV: any;
if (change.kind === 'E') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'N') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'D') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'A') {
oldV = (change as any).item.lhs;
newV = (change as any).item.rhs;
}
// Include category context for troubleshooting
let categoryA: any = 'Not Applicable';
let categoryB: any = 'Not Applicable';
if (change.path && change.path[0] !== undefined && typeof change.path[0] === 'number') {
const idx = change.path[0] as number;
const entryA = baselineData[idx] || {};
const entryB = otherData[idx] || {};
categoryA = entryA.category || 'Not Applicable';
categoryB = entryB.category || 'Not Applicable';
}
return {
[`更改类型:${selectedLanguages[diffBaselineId]} vs ${selectedLanguages[otherId]}`]: type,
"字段类型": pathStr,
[`模版值:${selectedLanguages[diffBaselineId]}`]: oldV || 'Not Applicable',
[`模版值:${selectedLanguages[otherId]}`]: newV || 'Not Applicable',
[`category:${selectedLanguages[diffBaselineId]}`]: categoryA,
[`category:${selectedLanguages[otherId]}`]: categoryB
};
});
// Write diff output
const outFile = `${selectedLanguages[diffBaselineId]}_vs_${selectedLanguages[otherId]}_nav_diff.json`;
const outPath = join(outDir, outFile);
writeFileSync(outPath, JSON.stringify(changes, null, 2), 'utf-8');
writeFileSync(outPath, JSON.stringify(semantic, null, 2), 'utf-8');
console.log(`✅ Nav diff between ${diffBaselineId} and ${otherId} written to ${outPath}`);
});
......@@ -8,12 +8,14 @@ export const getNavigationInfo = (items, pathArr: string[] = []) => {
// 构建对象路径
const currentPathArr = [...pathArr, `items[${idx}]`];
const type = item.type;
const category = item.title || 'No Applicable'
const itemsCount = item.items ? item.items.length : 0;
navigationResult.push({
patch: currentPathArr.join("."),
type: type,
itemsCount: itemsCount,
category,
dropdown_count: itemsCount,
});
// 递归处理 dropdown
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment