getCurrentVersion method

  1. @override
String getCurrentVersion()
override

Implementation

@override
String getCurrentVersion() {
  final file = File('pubspec.yaml');
  if (!file.existsSync()) {
    logger.error('pubspec.yaml not found');
    throw Exception('pubspec.yaml not found');
  }
  final content = file.readAsStringSync();
  final yaml = loadYaml(content);
  final Object? version = yaml['version'];
  if (version is! String || version.trim().isEmpty) {
    logger.error('Invalid or missing version in pubspec.yaml');
    throw Exception('Invalid or missing version in pubspec.yaml');
  }
  return version;
}