run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  final argGitsYaml = argResults.getOptionGitsYaml();

  YamlHelper.validateGitsYaml(argGitsYaml);
  final gitsYaml = YamlHelper.loadFileYaml(argGitsYaml);

  if (!gitsYaml.containsKey('coverage')) {
    StatusHelper.failed('gits.yaml not contain coverage config!');
  }

  final list = find('pubspec.yaml').toList();

  for (var pathPubspec in list) {
    final path = pathPubspec.replaceAll('/pubspec.yaml', '');
    final packageName = getYaml(pathPubspec)['name'];
    await createCoverageHelperTest(path, packageName);
  }

  await GitsModularHelper.coverage(concurrent: gitsYaml.concurrent);

  final pathCoverageLcov = 'coverage/lcov.info';
  if (!exists(pathCoverageLcov)) {
    touch(pathCoverageLcov, create: true);
  }

  for (var pathPubspec in list) {
    final path = pathPubspec.replaceAll('/pubspec.yaml', '');
    try {
      delete('$path/$pathCoverageHelper');
    } catch (e) {
      StatusHelper.warning('$path/$pathCoverageHelper not exists!');
    }

    final pathReplace = path.replaceAll('$current/', '');
    if (path != current) {
      replace('$path/$pathCoverageLcov', 'SF:lib/', 'SF:$pathReplace/lib/');
    }

    read('$path/$pathCoverageLcov').forEach((line) {
      pathCoverageLcov.append(line);
    });
  }

  if (Platform.isWindows) {
    print(
        'you must install perl and lcov then lcov remove file will be ignore to coverage manually & generate report to html manually.');
  }

  if (which('lcov').notfound) {
    StatusHelper.failed(
        'lcov not found, failed to remove ignore file to test.');
  }

  final lcovDir = gitsYaml['coverage']['lcov_dir'];
  final outputHtmlDir = gitsYaml['coverage']['output_html_dir'];
  final removeFile = (gitsYaml['coverage']['remove'] as List).join(' ');

  print("lcov --remove $lcovDir $removeFile -o $lcovDir");

  "lcov --remove $lcovDir $removeFile -o $lcovDir".run;

  if (which('genhtml').notfound) {
    StatusHelper.failed('failed cannot generate report lcov html.');
  }
  'genhtml $lcovDir -o $outputHtmlDir'.run;

  StatusHelper.success();
}