scan static method
The ecosystem packages in dir: each folder holding a pubspec whose
name is the folder's and starts with just_. Old copies (*_old) are
skipped.
Implementation
static List<Checkout> scan(Directory dir) {
final out = <Checkout>[];
if (!dir.existsSync()) return out;
for (final d in dir.listSync().whereType<Directory>()) {
final folder = d.uri.pathSegments.where((s) => s.isNotEmpty).last;
if (!folder.startsWith('just_') || folder.endsWith('_old')) continue;
final pubspec = File('${d.path}/pubspec.yaml');
if (!pubspec.existsSync()) continue;
final name = RegExp(
r'^name:\s*(\S+)',
multiLine: true,
).firstMatch(pubspec.readAsStringSync())?.group(1);
if (name == null || name != folder) continue;
out.add(Checkout(name, normalPath(d.absolute.path)));
}
out.sort((a, b) => a.name.compareTo(b.name));
return out;
}