const fs = require('fs'); const path = require('path'); const csvPath = 'scripts/dist/deps.all.csv'; const jsonDir = 'doc/curtis/prompt/scanimpl_analysis'; const modules = [ 'ScannerController', 'BusinessLogic', 'ImageProcessor', 'TransportManager', 'UIView' ]; function parseCSV(csv) { const lines = csv.split('\n'); const depsMap = {}; // Skip header for (let i = 1; i < lines.length; i++) { const line = lines[i].trim(); if (!line) continue; // Simple CSV parser (not handling quoted commas as there shouldn't be any in this specific CSV structure) const parts = line.split(','); if (parts.length < 5) continue; const methodName = parts[1].trim(); const dep = parts[4].trim(); if (methodName && dep) { if (!depsMap[methodName]) { depsMap[methodName] = new Set(); } depsMap[methodName].add(dep); } } // Convert sets to sorted arrays const result = {}; for (const name in depsMap) { result[name] = Array.from(depsMap[name]).sort(); } return result; } function updateJSONs() { const csvContent = fs.readFileSync(csvPath, 'utf8'); const depsMap = parseCSV(csvContent); modules.forEach(mod => { const filePath = path.join(jsonDir, `scanimpl_annalysis.${mod}.json`); if (!fs.existsSync(filePath)) { console.log(`File not found: ${filePath}`); return; } let methods = JSON.parse(fs.readFileSync(filePath, 'utf8')); let updatedCount = 0; methods = methods.map(method => { // Find matching methodName in depsMap // matcher example: "function TCB_IMGPSScanX.GetSiteOMR(" // methodName example: "GetSiteOMR" const foundDeps = new Set(); for (const methodName in depsMap) { // Use regex to match exact method name within the matcher string const regex = new RegExp(`\\b${methodName}\\b`); if (regex.test(method.matcher)) { depsMap[methodName].forEach(d => foundDeps.add(d)); } } if (foundDeps.size > 0) { method.deps = Array.from(foundDeps).sort(); updatedCount++; } else { // Keep existing deps if any, or initialize to empty array if required if (!method.deps) method.deps = []; } return method; }); fs.writeFileSync(filePath, JSON.stringify(methods, null, 2), 'utf8'); console.log(`Updated ${updatedCount} methods in ${filePath}`); }); } updateJSONs();