All files / lib/version-schemes semver.js

100% Statements 45/45
100% Branches 10/10
100% Functions 3/3
100% Lines 45/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461x 1x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 21x 23x 2x 2x 23x 23x 23x 1x 1x 8x 8x 1x 1x 8x 8x 1x 1x 1x 1x 1x 1x  
"use strict"
import semver from 'semver';
import util from 'util';
 
/**
 * This class defines versioning scheme following semantic versioning standard https://semver.org/ .
 */
class Semver {
 
  constructor(preReleaseVersion, releaseIncrementType, postReleaseIncrementType) {
    releaseIncrementType = releaseIncrementType || 'minor';
    postReleaseIncrementType = postReleaseIncrementType || 'patch';
 
    this.preReleaseVersion = preReleaseVersion;
 
    this.preReleaseComponent = semver.prerelease(preReleaseVersion) ? semver.prerelease(preReleaseVersion)[0] : 'pre';
 
    // has to rely on util format due to semver#coerce being no longer available in newer version of semver library
    this.preReleaseVersionWithoutPreReleaseComponent = util.format('%d.%d.%d',
      semver.major(this.preReleaseVersion),
      semver.minor(this.preReleaseVersion),
      semver.patch(this.preReleaseVersion));
 
    if (['minor', 'major'].includes(releaseIncrementType)) {
      this.releaseVersion = semver.inc(this.preReleaseVersionWithoutPreReleaseComponent, releaseIncrementType);
    } else {
      this.releaseVersion = this.preReleaseVersionWithoutPreReleaseComponent;
    }
 
    this.postReleaseVersion = semver.inc(this.releaseVersion, 'pre' + postReleaseIncrementType, this.preReleaseComponent);
  }
 
  getReleaseVersion() {
    return this.releaseVersion;
  }
 
  getPostReleaseVersion() {
    return this.postReleaseVersion;
  }
 
}
 
export {
  Semver as default
};