readPubspecVersion function

Future<String> readPubspecVersion(
  1. String filePath
)

Reads the version field from a pubspec.yaml file.

Implementation

Future<String> readPubspecVersion(String filePath) async {
  final content = await _readVersionFile(filePath);
  final Object? parsed = loadYaml(content);

  if (parsed is! YamlMap) {
    throw ShipworldException('Invalid pubspec.yaml at $filePath');
  }

  final Object? version = parsed['version'];

  if (version is! String) {
    throw ShipworldException('Missing version in $filePath');
  }

  return version;
}