bumpVersion method

Version bumpVersion(
  1. VersionBumpType bumpType
)

Returns a bumped Version, major, minor or patch

Always strips the pre-release identifiers. If the build information contains a single number, it is incremented.

Implementation

Version bumpVersion(VersionBumpType bumpType) {
  Version newVersion = () {
    switch (bumpType) {
      case VersionBumpType.major:
        return nextMajor;
      case VersionBumpType.minor:
        return nextMinor;
      case VersionBumpType.patch:
        return nextPatch;
    }
  }();

  // bump of build information is only safe when it contains a single number,
  // otherwise we don't know its incrementation schema and we leave it as is
  if (build.whereType<int>().length == 1) {
    final newBuild = build.map((e) => e is int ? e + 1 : e).join('.');
    newVersion = newVersion.copyWith(build: newBuild);
  } else {
    newVersion =
        newVersion.copyWith(build: build.isNotEmpty ? build.join('.') : null);
  }

  return newVersion;
}