From 0756bf12d10cf1b7f78c571de0a9ad69cbaeb7ca Mon Sep 17 00:00:00 2001
From: curtis <curtis@i-mps.com>
Date: 星期一, 30 三月 2026 14:24:17 +0800
Subject: [PATCH] fix: 更新內部引用方法參照

---
 scripts/scanimpl_annalysis_json_deps.js |   90 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/scripts/scanimpl_annalysis_json_deps.js b/scripts/scanimpl_annalysis_json_deps.js
new file mode 100644
index 0000000..2f68dd9
--- /dev/null
+++ b/scripts/scanimpl_annalysis_json_deps.js
@@ -0,0 +1,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();

--
Gitblit v1.8.0