findProjectRoot method

  1. @override
String findProjectRoot()
override

프로젝트 루트 디렉토리(pubspec.yaml이 있는 디렉토리)를 찾습니다.

Implementation

@override
String findProjectRoot() {
  Directory current = Directory.current;

  // 최대 20번 상위 디렉토리까지 검색
  for (int i = 0; i < 20; i++) {
    if (File(path.join(current.path, 'pubspec.yaml')).existsSync()) {
      print('Project root directory: ${current.path}');
      return current.path;
    }

    // 상위 디렉토리가 없으면 검색 종료
    Directory parent = Directory(path.dirname(current.path));
    if (parent.path == current.path) {
      break;
    }

    current = parent;
  }

  // 프로젝트 루트를 찾지 못한 경우
  print('Error: Could not find project root directory. Please run from a directory containing pubspec.yaml file.');
  exit(1);
}