const fs = require('fs');
|
const path = require('path');
|
|
const JSON_FILES = [
|
'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.BusinessLogic.json',
|
'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.ImageProcessor.json',
|
'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.ScannerController.json',
|
'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.TransportManager.json',
|
'doc/curtis/prompt/scanimpl_analysis/scanimpl_annalysis.UIView.json'
|
];
|
|
const TAGS_TO_FILE = {
|
// ScannerController
|
'ScannerController.acquisitionHandler': 'CB_IMGPSScanImp.scan.ac.pas',
|
'ScannerController.twainWrapper': 'CB_IMGPSScanImp.scan.twain.pas',
|
|
// TransportManager
|
'TransportManager.apiClient': 'CB_IMGPSScanImp.apiClient.pas',
|
'TransportManager.fileTransfer': 'CB_IMGPSScanImp.fileClient.pas',
|
'TransportManager.certificateManager': 'CB_IMGPSScanImp.cert.pas',
|
'TransportManager.payloadArchiver': 'CB_IMGPSScanImp.archiver.pas',
|
|
// ImageProcessor
|
'ImageProcessor.transformer': 'CB_IMGPSScanImp.img.trans.pas',
|
'ImageProcessor.converter': 'CB_IMGPSScanImp.img.cnv.pas',
|
'ImageProcessor.anchorAnalyzer': 'CB_IMGPSScanImp.img.anchor.pas',
|
'ImageProcessor.payloadArchiver': 'CB_IMGPSScanImp.archiver.pas',
|
|
// BusinessLogic
|
'BusinessLogic.systemInternal': 'CB_IMGPSScanImp.bloc.sys.pas',
|
'BusinessLogic.configRepository': 'CB_IMGPSScanImp.bloc.cfg.pas',
|
'BusinessLogic.ruleEngine': 'CB_IMGPSScanImp.bloc.rule.pas',
|
'BusinessLogic.entityMapping': 'CB_IMGPSScanImp.bloc.map.pas',
|
'BusinessLogic.fileManager': 'CB_IMGPSScanImp.bloc.file.pas',
|
'BusinessLogic.caseManager': 'CB_IMGPSScanImp.bloc.case.pas',
|
'BusinessLogic.entityModel': 'CB_IMGPSScanImp.bloc.model.pas',
|
'BusinessLogic.activeXWrapper': 'CB_IMGPSScanImp.bloc.ocx.pas',
|
|
// UIView
|
'初始化與生命週期': 'CB_IMGPSScanImp.view.lfcycle.pas',
|
'UIView.events': 'CB_IMGPSScanImp.view.evt.pas',
|
'UIView.inputHandler': 'CB_IMGPSScanImp.view.evt.pas',
|
'UIView.configRepository': 'CB_IMGPSScanImp.view.cfg.pas',
|
'UIView.ruleEngine': 'CB_IMGPSScanImp.view.rule.pas',
|
'UIView.entityMapping': 'CB_IMGPSScanImp.view.map.pas',
|
'UIView.fileManager': 'CB_IMGPSScanImp.view.file.pas',
|
'UIView.caseManager': 'CB_IMGPSScanImp.view.case.pas',
|
'UIView.entityModel': 'CB_IMGPSScanImp.view.model.pas',
|
'UIView.activeXWrapper': 'CB_IMGPSScanImp.view.ocx.pas',
|
'UIView.treeView': 'CB_IMGPSScanImp.view.tree.pas',
|
'UIView.toolBar': 'CB_IMGPSScanImp.view.toolbar.pas',
|
'UIView.imageScrollBox': 'CB_IMGPSScanImp.view.isb.pas',
|
'UIView.popupMenu': 'CB_IMGPSScanImp.view.menu.pas',
|
'UIView.listView': 'CB_IMGPSScanImp.view.list.pas',
|
};
|
|
const SRC_FILE = 'CB_IMGPSScanImp.pas.bk';
|
|
function main() {
|
const originalContent = fs.readFileSync(SRC_FILE, 'utf8');
|
const lines = originalContent.split(/\r?\n/);
|
|
let successCount = 0;
|
let failCount = 0;
|
|
JSON_FILES.forEach(jsonFile => {
|
console.log(`Checking ${jsonFile}...`);
|
const data = JSON.parse(fs.readFileSync(jsonFile, 'utf8'));
|
data.forEach(m => {
|
const lIndex = parseInt(m.lIndex);
|
const rIndex = parseInt(m.rIndex);
|
if (lIndex <= 0 || rIndex <= 0) return;
|
|
// Find the target file
|
let targetFile = null;
|
for (const tag of m.tags) {
|
if (TAGS_TO_FILE[tag]) {
|
targetFile = TAGS_TO_FILE[tag];
|
break;
|
}
|
}
|
|
if (targetFile) {
|
if (!fs.existsSync(targetFile)) {
|
console.error(`Error: Target file ${targetFile} does not exist.`);
|
failCount++;
|
return;
|
}
|
|
const subFileContent = fs.readFileSync(targetFile, 'utf8');
|
const expectedCodeLines = lines.slice(lIndex - 1, rIndex);
|
const expectedCode = expectedCodeLines.join('\n');
|
|
// Check if expectedCode exists in subFileContent
|
// Note: the subFileContent has an extra \n between methods
|
if (subFileContent.includes(expectedCode)) {
|
successCount++;
|
} else {
|
console.error(`Error: Code for ${m.matcher} (line ${lIndex}-${rIndex}) not found in ${targetFile}`);
|
failCount++;
|
}
|
}
|
});
|
});
|
|
console.log(`\nVerification Results:`);
|
console.log(` Success: ${successCount}`);
|
console.log(` Fail: ${failCount}`);
|
|
if (failCount > 0) {
|
process.exit(1);
|
}
|
}
|
|
main();
|