generateReport static method
Generate a text report.
Implementation
static String generateReport() {
final result = analyze();
final buffer = StringBuffer();
buffer.writeln('═══════════════════════════════════════════════════════════');
buffer.writeln(' TREE SHAKING ANALYSIS REPORT');
buffer.writeln('═══════════════════════════════════════════════════════════');
buffer.writeln();
buffer.writeln('Generated: ${result.timestamp.toLocal()}');
buffer.writeln();
buffer.writeln('┌─────────────────────────────────────────────────────────┐');
buffer.writeln('│ SUMMARY │');
buffer.writeln('├─────────────────────────────────────────────────────────┤');
buffer.writeln('│ Total Components: ${result.totalComponents.toString().padLeft(6)} │');
buffer.writeln('│ Used Components: ${result.usedComponents.toString().padLeft(6)} (${result.usagePercentage.toStringAsFixed(1)}%) │');
buffer.writeln('│ Unused Components: ${result.unusedComponents.toString().padLeft(6)} │');
buffer.writeln('├─────────────────────────────────────────────────────────┤');
buffer.writeln('│ Total Size (est): ${_formatBytes(result.totalSizeBytes).padLeft(10)} │');
buffer.writeln('│ Used Size: ${_formatBytes(result.usedSizeBytes).padLeft(10)} │');
buffer.writeln('│ Potential Savings: ${_formatBytes(result.unusedSizeBytes).padLeft(10)} (${result.potentialSavingsPercent.toStringAsFixed(1)}%) │');
buffer.writeln('└─────────────────────────────────────────────────────────┘');
buffer.writeln();
if (result.unusedComponentsList.isNotEmpty) {
buffer.writeln('Unused Components:');
final sortedUnused = result.unusedComponentsList.toList()
..sort((a, b) => b.estimatedSizeBytes.compareTo(a.estimatedSizeBytes));
for (final component in sortedUnused.take(20)) {
buffer.writeln(' - ${component.name} (${_formatBytes(component.estimatedSizeBytes)})');
}
if (sortedUnused.length > 20) {
buffer.writeln(' ... and ${sortedUnused.length - 20} more');
}
buffer.writeln();
}
if (result.recommendations.isNotEmpty) {
buffer.writeln('Recommendations:');
for (var i = 0; i < result.recommendations.length; i++) {
buffer.writeln(' ${i + 1}. ${result.recommendations[i]}');
}
}
return buffer.toString();
}