curtis
13小時前 62c5adb8641e8626a056abc773b72449152d8ae9
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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();