LCOV - code coverage report
Current view: top level - src/cli - dart_cli.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 27 27 100.0 %
Date: 2024-03-25 10:36:11 Functions: 0 0 -

          Line data    Source code
       1             : part of 'cli.dart';
       2             : 
       3             : /// Dart CLI
       4             : class Dart {
       5             :   /// Determine whether dart is installed.
       6           1 :   static Future<bool> installed({
       7             :     required Logger logger,
       8             :   }) async {
       9             :     try {
      10           2 :       await _Cmd.run('dart', ['--version'], logger: logger);
      11             :       return true;
      12             :     } catch (_) {
      13             :       return false;
      14             :     }
      15             :   }
      16             : 
      17             :   /// Install dart dependencies (`dart pub get`).
      18           1 :   static Future<bool> pubGet({
      19             :     required Logger logger,
      20             :     String cwd = '.',
      21             :     bool recursive = false,
      22             :     Set<String> ignore = const {},
      23             :   }) async {
      24             :     final initialCwd = cwd;
      25             : 
      26           1 :     final result = await _runCommand(
      27           1 :       cmd: (cwd) async {
      28           1 :         final relativePath = p.relative(cwd, from: initialCwd);
      29             :         final path =
      30           4 :             relativePath == '.' ? '.' : '.${p.context.separator}$relativePath';
      31             : 
      32           1 :         final installProgress = logger.progress(
      33           1 :           'Running "dart pub get" in $path',
      34             :         );
      35             : 
      36             :         try {
      37           1 :           await _verifyGitDependencies(cwd, logger: logger);
      38             :         } catch (_) {
      39           1 :           installProgress.fail();
      40             :           rethrow;
      41             :         }
      42             : 
      43             :         try {
      44           1 :           return await _Cmd.run(
      45             :             'dart',
      46           1 :             ['pub', 'get'],
      47             :             workingDirectory: cwd,
      48             :             logger: logger,
      49             :           );
      50             :         } finally {
      51           1 :           installProgress.complete();
      52             :         }
      53             :       },
      54             :       cwd: cwd,
      55             :       recursive: recursive,
      56             :       ignore: ignore,
      57             :     );
      58           5 :     return result.every((e) => e.exitCode == ExitCode.success.code);
      59             :   }
      60             : 
      61             :   /// Apply all fixes (`dart fix --apply`).
      62           1 :   static Future<void> applyFixes({
      63             :     required Logger logger,
      64             :     String cwd = '.',
      65             :     bool recursive = false,
      66             :     Set<String> ignore = const {},
      67             :   }) async {
      68             :     if (!recursive) {
      69           2 :       final pubspec = File(p.join(cwd, 'pubspec.yaml'));
      70           1 :       if (!pubspec.existsSync()) throw PubspecNotFound();
      71             : 
      72           1 :       await _Cmd.run(
      73             :         'dart',
      74           1 :         ['fix', '--apply'],
      75             :         workingDirectory: cwd,
      76             :         logger: logger,
      77             :       );
      78             :       return;
      79             :     }
      80             : 
      81           1 :     final processes = _Cmd.runWhere(
      82           2 :       run: (entity) => _Cmd.run(
      83             :         'dart',
      84           1 :         ['fix', '--apply'],
      85           2 :         workingDirectory: entity.parent.path,
      86             :         logger: logger,
      87             :       ),
      88           3 :       where: (entity) => !ignore.excludes(entity) && _isPubspec(entity),
      89             :       cwd: cwd,
      90             :     );
      91             : 
      92           1 :     if (processes.isEmpty) throw PubspecNotFound();
      93             : 
      94           1 :     await Future.wait<void>(processes);
      95             :   }
      96             : }

Generated by: LCOV version 1.15