verifiedProjectDirectory method

Directory verifiedProjectDirectory()

Selects and verifies the project directory that is either specified by the global configuration, or files found near the current directory.

Verifies that the directory is a valid Serverpod server directory using isServerpodServerDirectory and gives feedback to the user.

Throws ExitException if no valid project directory could be determined.

Implementation

Directory verifiedProjectDirectory() {
  final selectedProjectDir = selectProjectDirectory();
  if (selectedProjectDir == null) {
    logger.error(
      'No valid Serverpod server directory selected.',
      hint:
          "Provide the project's server directory with the `--project-dir` option and try again.",
    );
    throw ErrorExitException('No project directory selected.');
  }

  final projectDirectory = Directory(selectedProjectDir);

  if (!isServerpodServerDirectory(projectDirectory)) {
    logProjectDirIsNotAServerpodServerDirectory(logger, selectedProjectDir);
    throw ErrorExitException(
        'The directory is not a Serverpod server directory.');
  }

  return projectDirectory;
}