TenantProjectPubspec.fromFile constructor

TenantProjectPubspec.fromFile(
  1. File pubspecFile
)

Reads and parses the given pubspec.yaml file.

If the pubspec.yaml file is not found or if it cannot be parsed, error messages are printed to logger if provided, and ErrorExitException is thrown.

Implementation

factory TenantProjectPubspec.fromFile(final File pubspecFile) {
  if (!pubspecFile.existsSync()) {
    throw FailureException(
      error:
          'Could not find `pubspec.yaml` in directory `${pubspecFile.parent.path}`.',
      hint: "Provide the project's server directory and try again.",
    );
  }

  final Pubspec pubspec;
  try {
    pubspec = Pubspec.parse(pubspecFile.readAsStringSync());
  } catch (e) {
    throw FailureException(
      error: 'Failed to parse pubspec.yaml: ${e.toString()}',
      hint: 'Please fix the errors and try again.',
    );
  }
  return TenantProjectPubspec(pubspec);
}