updateYamlVersionInPubspec function
Updates the 'version' field in the pubspec.yaml file.
This function reads the pubspec.yaml file, updates its 'version' field
to the newVersion using yaml_edit, and then writes the modified
content back to the file.
newVersion The new version string to set in pubspec.yaml.
Throws a FileSystemException if the pubspec.yaml file cannot be read or written.
Throws a YamlException if the pubspec.yaml content is invalid.
Implementation
Future<void> updateYamlVersionInPubspec(String newVersion) async {
final pubspecFilePath = Constants.pubspecFilePath;
final pubspecContent = File(pubspecFilePath).readAsStringSync();
final yamlEditor = YamlEditor(pubspecContent);
yamlEditor.update(['version'], newVersion);
File(pubspecFilePath).writeAsStringSync(yamlEditor.toString());
logger.i('✅ Updated version in ${Constants.pubspecFilePath} to $newVersion');
}