blob: ab5e93b38da460f7f9fb47b05655f165d00a8106 [file] [log] [blame]
import 'dart:io';
import 'package:path/path.dart' as path;
bool _hasPubspec(Directory directory) {
return directory.listSync().any(
(entity) =>
FileSystemEntity.isFileSync(entity.path) &&
path.basename(entity.path) == 'pubspec.yaml',
);
}
Directory projectRootDirectory() {
var current = Directory.current.absolute;
while (!_hasPubspec(current)) {
if (current.path == current.parent.path) {
throw Exception('Reached file system root when seeking project root.');
}
current = current.parent;
}
return current;
}