loadPubspec method

Pubspec loadPubspec({
  1. String? packageName,
})

Loads the pubspec file for the current project.

Implementation

Pubspec loadPubspec( { String? packageName }) {
  final pathPubspec = generator.pathPubspecYaml;
  if(!generator.fileExists(pathPubspec)) {
    throw AFCommandError(error: "The file ${pathPubspec.last} must exist in the folder from which you are running this command");
  }

  final filePubspec = generator.readFile(this, pathPubspec);
  final pubspec = filePubspec.loadPubspec();
  final name = pubspec.name;

  if(packageName != null && name != packageName) {
    throw AFCommandError(error: "Expected yourpackagename to be $name but found $packageName");
  }

  return pubspec;
}