getHighestVersion method

Version getHighestVersion()

When releasing we need to ensure that the version no. of any package is higher than the previously released package no. So we need to find the highest version no. from all of the packages.

Implementation

Version getHighestVersion() {
  final lowest = Version.parse('0.0.1-dev.0');
  var highestVersion = lowest;

  for (final package in packages) {
    final pubspec = PubSpec.fromFile(join(package.path, 'pubspec.yaml'));
    if (pubspec.version != null &&
        pubspec.version!.compareTo(highestVersion) > 0) {
      highestVersion = pubspec.version!;
    }
  }

  /// If no package had a version no.
  if (highestVersion == lowest) {
    highestVersion = Version.parse('0.0.1');
  }

  return highestVersion;
}