compareVersions method
Compares two versions and returns the newer version if it meets the specified update type criteria.
current is the current version of the package.
newer is the newer version of the package.
type is the type of update to check for (major, minor, or patch).
Implementation
Version? compareVersions(Version current, Version newer, Types type) {
switch (type) {
case Types.major:
if (current.major < newer.major) {
return newer;
}
break;
case Types.minor:
if (current.minor < newer.minor && current.major >= newer.major) {
return newer;
}
break;
case Types.patch:
if (current.patch < newer.patch && current.minor >= newer.minor && current.major >= newer.major) {
return newer;
}
break;
}
return null;
}