runSequence static method

Future<void> runSequence(
  1. void runner(
    1. String path
    ), {
  2. bool ignorePubWorkspaces = false,
})

Implementation

static Future<void> runSequence(
  void Function(String path) runner, {
  bool ignorePubWorkspaces = false,
}) async {
  final workingDirectoryFlutter = find('pubspec.yaml', workingDirectory: '.')
      .toList()
      .where(
        (element) {
          if (ignorePubWorkspaces) {
            return true;
          }
          final resolution = 'resolution';

          final yaml = YamlHelper.loadFileYaml(element);
          final hasResolution = yaml.containsKey(resolution);

          return !hasResolution;
        },
      )
      .map((e) => e.replaceAll('${separator}pubspec.yaml', ''))
      .sorted((a, b) =>
          b.split(separator).length.compareTo(a.split(separator).length));

  List<Future Function()> futures = [];

  for (var e in workingDirectoryFlutter) {
    futures.add(() async {
      final path = e.replaceAll(current, '.');
      try {
        printMessage('πŸš€ $path');
        runner.call(path);
        printMessage('βœ…  $path');
      } catch (e) {
        printMessage('❌  $path');
        rethrow;
      }
    });
  }

  final length = futures.length;
  printMessage('πŸ“¦ Total Packages: $length');
  printMessage('---------------------------------------');
  for (var element in futures) {
    await element.call();
  }
}