findProjects static method

Future<List<CommandContext>> findProjects({
  1. String scan = '.',
  2. bool recursive = true,
  3. List<String>? include,
  4. List<String>? exclude,
  5. Set<Type>? requiredNatures,
})

Get list of projects without executing anything.

Useful for scripts that need to iterate manually or preview results.

Implementation

static Future<List<CommandContext>> findProjects({
  String scan = '.',
  bool recursive = true,
  List<String>? include,
  List<String>? exclude,
  Set<Type>? requiredNatures,
}) async {
  final info = ProjectTraversalInfo(
    scan: scan,
    recursive: recursive,
    executionRoot: Directory.current.path,
    projectPatterns: include ?? [],
    excludeProjects: exclude ?? [],
  );

  final scanner = FolderScanner();
  final filter = FilterPipeline();
  final detector = NatureDetector();

  final folders = await scanner.scan(
    info.scan,
    recursive: info.recursive,
    recursionExclude: info.recursionExclude,
  );

  final filtered = filter.applyProjectFilters(folders, info);

  return filtered
      .map((folder) {
        final natures = detector.detectNatures(folder);
        folder.natures.addAll(natures);
        return CommandContext(
          fsFolder: folder,
          natures: natures,
          executionRoot: info.executionRoot,
        );
      })
      .where(
        (ctx) =>
            requiredNatures == null ||
            requiredNatures.every(
              (t) => ctx.natures.any((n) => n.runtimeType == t),
            ),
      )
      .toList();
}