import fs from "node:fs"; import path from "node:path"; const paths = [ "..\\PackageSources\\ModelBehaviorDefs\\TFDi_Design\\MD11\\Cabin", "..\\PackageSources\\ModelBehaviorDefs\\TFDi_Design\\MD11\\FlightDeck", ]; let tips = fs.readFileSync("tooltips.csv", { encoding: "utf-8" }).split("\n"); tips = tips.reduce((prev, tip, index) => { if (index == 0) return {}; const [file, templateName, nodeID, tooltip] = tip.split("|"); if (!prev[file]) prev[file] = {}; if (!prev[file][templateName]) prev[file][templateName] = {}; prev[file][templateName][nodeID] = tooltip; return prev; }, {}); paths.forEach((_path) => { const files = fs.readdirSync(_path); files.forEach((file) => { const _file = fs.readFileSync(path.join(_path, file), { encoding: "utf-8", }); const lines = _file.split("\n"); let templateName; let tip; let nodeID; for (let index = 0; index < lines.length; index++) { const line = lines[index].trim(); const open = [...line.matchAll(/^$/gi)]; const close = [...line.matchAll(/^<\/UseTemplate>$/gi)]; const _nodeID = [...line.matchAll(/^(.*)<\/NODE_ID>$/gi)]; const _tip = [...line.matchAll(/^(.*)<\/TOOLTIPID>$/gi)]; if (open.length > 0) { templateName = open[0][1]; } else if (_tip.length > 0) { tip = _tip[0][1]; } else if (_nodeID.length > 0) { nodeID = _nodeID[0][1]; } else if (close.length > 0) { templateName = undefined; tip = undefined; nodeID = undefined; continue; } if (templateName && tip && nodeID) { const _file = tips[file]; const _templateName = _file?.[templateName]; const __tip = _templateName?.[nodeID]; if (__tip) { if (__tip !== tip) { console.log("\x1b[31;1mTips differ", file, nodeID, "\x1b[0m"); console.log("\x1b[32mXML:", tip, "\x1b[0m"); console.log("\x1b[33mCSV:", __tip, "\x1b[0m"); console.log(); templateName = undefined; tip = undefined; nodeID = undefined; continue; } } } } }); });