index.ts
2.67 KB
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
/**
* Report subnode for validation loop.
* Orchestrates report generation: validation results → userReport → HTML file.
*
* This is called at the END of validation-loop with pre-computed validation results.
* Delegates to ReportTool for visualization and HTML generation.
*/
import { logger } from '../../../utils/logger';
import { ReportTool } from '../../../tools/report-tool';
import type { ReportOptions, ReportResult } from '../types';
/**
* Generate complete validation report: userReport structure + HTML file.
* This is the single entry point for all reporting in the validation loop.
*/
export async function report(options: ReportOptions): Promise<ReportResult> {
const tool = new ReportTool();
try {
// Step 1: Generate userReport with screenshots
logger.printInfoLog('正在生成校验报告结构…');
const reportResult = await tool.generateReport({
validationResult: options.validationResult,
figmaThumbnailUrl: options.figmaThumbnailUrl,
cachedFigmaThumbnailBase64: options.cachedFigmaThumbnailBase64,
designOffset: options.designOffset,
outputDir: options.outputDir,
serverUrl: options.serverUrl,
savedRenderMarkedPath: options.savedRenderMarkedPath,
savedTargetMarkedPath: options.savedTargetMarkedPath,
});
// Step 2: Generate HTML file from userReport
logger.printInfoLog('正在生成 HTML 报告文件…');
const htmlResult = await tool.generateHtml(reportResult.userReport, options.outputDir);
if (!htmlResult.success) {
logger.printWarnLog(`生成 HTML 失败:${htmlResult.error}`);
return {
success: false,
error: htmlResult.error,
userReport: reportResult.userReport,
};
}
logger.printSuccessLog(`报告已生成:${htmlResult.htmlPath}`);
return {
success: true,
htmlPath: htmlResult.htmlPath,
userReport: reportResult.userReport,
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.printErrorLog(`生成报告出错:${errorMessage}`);
// Fallback: Create minimal report
const minimalReport = tool.createMinimalReport({
serverUrl: options.serverUrl,
figmaThumbnailUrl: options.figmaThumbnailUrl,
mae: options.validationResult?.mae,
sae: options.validationResult?.sae,
});
return {
success: false,
error: errorMessage,
userReport: minimalReport,
};
}
}