nextMetadataVersion function

int nextMetadataVersion({
  1. required String currentVersion,
  2. required List<String> priorVersions,
  3. required String metadata,
})

Implementation

int nextMetadataVersion({
  required String currentVersion,
  required List<String> priorVersions,
  required String metadata,
}) {
  var res = priorVersions
      .map((x) => x.trim())
      .map((x) => Version.parse(x))
      .where((x) => ((Version version) =>
          x.major == version.major &&
          x.minor == version.minor &&
          x.patch == version.patch &&
          x.leadingPreRelease() == metadata)(Version.parse(currentVersion)))
      .where((x) => x.leadingPreRelease() == metadata)
      .where((x) => x.hasNumericPreRelease())
      .map((x) => x.numericPrelease())
      .toList()
        ..sort();

  return res.isNotEmpty ? res.last + 1 : 0;
}