Commit 900dd84d by Lin Wang

feat: get the diff nav data

parent 2066486e
...@@ -21,16 +21,13 @@ ...@@ -21,16 +21,13 @@
"detect:ai": "USE_AI_SELECTORS=true bun run detect", "detect:ai": "USE_AI_SELECTORS=true bun run detect",
"fix": "DETECTION_MODE=fix bun run src/detect_section_selector_masters/index.ts", "fix": "DETECTION_MODE=fix bun run src/detect_section_selector_masters/index.ts",
"fix:ai": "USE_AI_SELECTORS=true bun run fix", "fix:ai": "USE_AI_SELECTORS=true bun run fix",
"nav": "DETECTION_MODE=extractNav bun run src/detect_section_selector_masters/index.ts", "diff-nav": "DETECTION_MODE=extractNav bun run src/detect_section_selector_masters/index.ts && bun run src/detect_section_selector_masters/diffNavWithDeepDiff.ts",
"nav:ai": "USE_AI_SELECTORS=true bun run nav", "diff-nav:ai": "USE_AI_SELECTORS=true bun run diff-nav",
"diff": "bun run src/detect_section_selector_masters/diffWithDeepDiff.ts", "diff": "bun run src/detect_section_selector_masters/diffWithDeepDiff.ts",
"diff:ai": "USE_AI_SELECTORS=true bun run diff", "diff:ai": "USE_AI_SELECTORS=true bun run diff",
"task": "bun run extract && bun run diff", "task": "bun run extract && bun run diff",
"task:ai": "bun run extract:ai && bun run diff:ai", "task:ai": "bun run extract:ai && bun run diff:ai",
"send-diff": "bun run src/detect_section_selector_masters/sendDiffToSlack.ts",
"send-gsheet": "bun run src/detect_section_selector_masters/sendDiffToGoogleSheets.ts", "send-gsheet": "bun run src/detect_section_selector_masters/sendDiffToGoogleSheets.ts",
"task:slack": "bun run task && bun run send-diff",
"task:slack:ai": "bun run task:ai && bun run send-diff",
"task:gsheet": "bun run task && bun run send-gsheet", "task:gsheet": "bun run task && bun run send-gsheet",
"task:gsheet:ai": "bun run task:ai && USE_AI_SELECTORS=true bun run send-gsheet", "task:gsheet:ai": "bun run task:ai && USE_AI_SELECTORS=true bun run send-gsheet",
"notify-slack": "bun run src/detect_section_selector_masters/sendNotifySlack.ts" "notify-slack": "bun run src/detect_section_selector_masters/sendNotifySlack.ts"
......
// @ts-nocheck
import { diff } from 'deep-diff';
import { readFileSync, writeFileSync, mkdirSync, rmSync, readdirSync } from 'fs';
import { join } from 'path';
import { section_selectors, sectionSelectorLanguages, ai_section_selectors, aiSectionSelectorsLanguages, diffBaselineId } from '../constant/section_selectors';
const useAiSelectors = process.env.USE_AI_SELECTORS === 'true';
// Directory containing navigation JSON outputs to compare
const srcDir = 'src/detect_section_selector_masters/extractNavOutput';
// Directory to write nav diff results
const outDir = useAiSelectors ? 'src/detect_section_selector_masters/diffAINavWithBaseline' : 'src/detect_section_selector_masters/diffNavWithBaseline';
// Remove existing output folder if it exists
rmSync(outDir, { recursive: true, force: true });
// Ensure output directory exists
mkdirSync(outDir, { recursive: true });
const selectedLanguages = useAiSelectors ? aiSectionSelectorsLanguages : sectionSelectorLanguages;
// Baseline nav file
const baselineFile = `${diffBaselineId}_extractNav.json`;
const baselinePath = join(srcDir, baselineFile);
const baselineData = JSON.parse(readFileSync(baselinePath, 'utf-8'));
// Get all nav files excluding baseline
const allFiles = readdirSync(srcDir).filter(f => f.endsWith('_extractNav.json') && f !== baselineFile);
allFiles.forEach(file => {
const otherId = file.split('_')[0];
const otherPath = join(srcDir, file);
const otherData = JSON.parse(readFileSync(otherPath, 'utf-8'));
// Compute differences
const changes = diff(baselineData, otherData) || [];
// 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');
console.log(`✅ Nav diff between ${diffBaselineId} and ${otherId} written to ${outPath}`);
});
...@@ -2,9 +2,7 @@ import { writeFileSync, mkdirSync, existsSync, rmSync } from 'fs' ...@@ -2,9 +2,7 @@ import { writeFileSync, mkdirSync, existsSync, rmSync } from 'fs'
import { fetchSiteData } from '../clients/bobcat/SiteInfo' import { fetchSiteData } from '../clients/bobcat/SiteInfo'
import { import {
section_selectors, section_selectors,
sectionSelectorLanguages,
ai_section_selectors, ai_section_selectors,
aiSectionSelectorsLanguages
} from '../constant/section_selectors' } from '../constant/section_selectors'
import { mainParse } from './handlePageContent' import { mainParse } from './handlePageContent'
......
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