resolveFlutterAndDart<T> method

({Iterable<T> dart, Iterable<T> flutter, Iterable<(DetermineFlutterOrDart, T)> ordered}) resolveFlutterAndDart<T>(
  1. Iterable<String> pubspecs,
  2. T getCommandToRun(
    1. DetermineFlutterOrDart flutterOrDart
    ), {
  3. required bool dartOnly,
  4. required bool flutterOnly,
})

Implementation

({
  Iterable<T> dart,
  Iterable<T> flutter,
  Iterable<(DetermineFlutterOrDart, T)> ordered,
}) resolveFlutterAndDart<T>(
  Iterable<String> pubspecs,
  T Function(DetermineFlutterOrDart flutterOrDart) getCommandToRun, {
  required bool dartOnly,
  required bool flutterOnly,
}) {
  final commands = (
    dart: <T>[],
    flutter: <T>[],
    ordered: <(DetermineFlutterOrDart, T)>[],
  );

  for (final pubspec in pubspecs) {
    final flutterOrDart = DetermineFlutterOrDart(
      pubspecYaml: pubspec,
      pubspecLock: pubspecLock,
      findFile: findFile,
    );

    final project = path.dirname(pubspec);

    final relativeDir = path.relative(
      project,
      from: fs.currentDirectory.path,
    );

    if (dartOnly ^ flutterOnly) {
      if (dartOnly && flutterOrDart.isFlutter) {
        logger.detail('Skipping flutter project: $relativeDir');
        continue;
      } else if (flutterOnly && flutterOrDart.isDart) {
        logger.detail('Skipping dart project: $relativeDir');
        continue;
      }
    }

    final command = getCommandToRun(flutterOrDart);

    commands.ordered.add((flutterOrDart, command));
    if (flutterOrDart.isFlutter) {
      commands.flutter.add(command);
    } else {
      commands.dart.add(command);
    }
  }

  return commands;
}