generate static method

Future<String> generate({
  1. required List<DiscoveredScreen> screens,
  2. required List<KnownRisk> knownRisks,
  3. required String projectPath,
  4. required String projectName,
})

Generate an HTML health report and auto-open it in the browser. Returns the path to the saved file.

Implementation

static Future<String> generate({
  required List<DiscoveredScreen> screens,
  required List<KnownRisk> knownRisks,
  required String projectPath,
  required String projectName,
}) async {
  final timestamp = DateTime.now();
  final ts = '${timestamp.year}'
      '${timestamp.month.toString().padLeft(2, '0')}'
      '${timestamp.day.toString().padLeft(2, '0')}_'
      '${timestamp.hour.toString().padLeft(2, '0')}'
      '${timestamp.minute.toString().padLeft(2, '0')}';

  final outDir = Directory('$projectPath/.dangi_doctor');
  if (!outDir.existsSync()) outDir.createSync(recursive: true);
  final outPath = '${outDir.path}/report_$ts.html';

  final html = _buildHtml(
    screens: screens,
    knownRisks: knownRisks,
    projectName: projectName,
    timestamp: timestamp,
  );

  File(outPath).writeAsStringSync(html);
  print('\nšŸ“Š Report saved: $outPath');

  // Auto-open
  try {
    if (Platform.isMacOS) {
      await Process.run('open', [outPath]);
    } else if (Platform.isLinux) {
      await Process.run('xdg-open', [outPath]);
    } else if (Platform.isWindows) {
      await Process.run('start', [outPath], runInShell: true);
    }
  } catch (_) {}

  return outPath;
}