getRoot method

Future<Directory?> getRoot()

Implementation

Future<Directory?> getRoot() async {
  File? file;
  Directory? directory = this;
  while (file == null && directory != null) {
    final pubspec = directory.childFile('pubspec.yaml');

    if (await pubspec.exists()) {
      file = pubspec;
      break;
    }

    directory = directory.parent;
  }

  if (file == null) {
    return null;
  }

  return directory;
}