updateVersionFromDetails function
Updates the pubspec.yaml and versiong.g.dart with the new version no.
Implementation
void updateVersionFromDetails(
Version? newVersion, PubSpecDetails pubspecDetails) {
print('');
// recreate the version file
final pathToPackgeRoot = dirname(pubspecDetails.path);
print(green('Updated pubspec.yaml version to $newVersion'));
// updated the verions no.
pubspecDetails.pubspec.version = newVersion;
// write new version.g.dart file.
final pathToVersion = versionPath(pathToPackgeRoot);
final pathToVersionLibrary = versionLibraryPath(pathToPackgeRoot);
if (!exists(pathToVersion)) {
createDir(pathToVersion, recursive: true);
}
print('Regenerating version file at ${absolute(pathToVersionLibrary)}');
pathToVersionLibrary
..write('/// GENERATED BY pub_release do not modify.')
..append('/// ${pubspecDetails.pubspec.name} version')
..append("String packageVersion = '$newVersion';");
// rewrite the pubspec.yaml with the new version
pubspecDetails.pubspec.saveToFile(pubspecDetails.path);
/// pause for a moment incase an IDE is monitoring the pubspec.yaml
/// changes. If we move too soon the .dart_tools directory may not exist.
sleep(2);
}