saveAnalysisReport method
Implementation
Future<void> saveAnalysisReport(
AnalysisResult analysis,
String outputPath,
) async {
try {
final directory = Directory(path_util.dirname(outputPath));
if (!await directory.exists()) {
await directory.create(recursive: true);
}
final file = File(outputPath);
final report = {
'timestamp': DateTime.now().toIso8601String(),
'totalAssets': analysis.assets.length,
'totalSize': analysis.getTotalSize(),
'sizeByType': analysis.getSizeByType(),
'assets': analysis.assets
.map((asset) => {
'name': asset.info.name,
'path': asset.info.path,
'size': asset.info.size,
'type': asset.info.type,
'lastModified': asset.info.lastModified.toIso8601String(),
'imageInfo': asset.imageInfo?.toJson(),
'issues': asset.issues
.map((issue) => {
'type': issue.type.toString(),
'message': issue.message,
'severity': issue.severity.toString(),
})
.toList(),
})
.toList(),
};
await file.writeAsString(
JsonEncoder.withIndent(' ').convert(report),
);
} catch (e) {
throw AssetOptException('Failed to save analysis report: $e');
}
}