updateVersion function
Updates the pubspec.yaml and versiong.g.dart with the new version no.
Implementation
void updateVersion(Version? newVersion, PubSpec pubspec, String pubspecPath) {
print('');
// recreate the version file
final packageRootPath = dirname(pubspecPath);
print('Updating pubspec.yaml version.');
// updated the verions no.
pubspec.version = newVersion;
// write new version.g.dart file.
final versionPath = join(packageRootPath, 'lib', 'src', 'version');
if (!exists(versionPath)) createDir(versionPath, recursive: true);
final versionFile = join(versionPath, 'version.g.dart');
print('Regenerating version file at ${absolute(versionFile)}');
versionFile.write('/// GENERATED BY pub_release do not modify.');
versionFile.append('/// ${pubspec.name} version');
versionFile.append("String packageVersion = '$newVersion';");
// rewrite the pubspec.yaml with the new version
pubspec.saveToFile(pubspecPath);
}