2018-09-02 10:26:04 +00:00
|
|
|
import * as plugins from './smartversion.plugins';
|
2017-08-17 14:15:47 +00:00
|
|
|
|
2018-09-02 10:26:04 +00:00
|
|
|
import { SemVer } from 'semver';
|
2017-08-17 14:15:47 +00:00
|
|
|
|
|
|
|
export class SmartVersion {
|
2019-09-11 15:42:34 +00:00
|
|
|
public semver: SemVer;
|
|
|
|
public versionString: string;
|
|
|
|
public update = {
|
2017-08-17 14:15:47 +00:00
|
|
|
patch: () => {
|
2018-09-02 10:26:04 +00:00
|
|
|
this.semver.patch = this.semver.patch + 1;
|
2017-08-17 14:15:47 +00:00
|
|
|
},
|
|
|
|
minor: () => {
|
2018-09-02 10:26:04 +00:00
|
|
|
this.semver.minor = this.semver.minor + 1;
|
2017-08-17 14:15:47 +00:00
|
|
|
},
|
|
|
|
major: () => {
|
2018-09-02 10:26:04 +00:00
|
|
|
this.semver.major = this.semver.major + 1;
|
2021-04-25 08:52:39 +00:00
|
|
|
},
|
2018-09-02 10:26:04 +00:00
|
|
|
};
|
2017-08-17 14:15:47 +00:00
|
|
|
|
2018-09-02 10:26:04 +00:00
|
|
|
constructor(semVerStringArg: string) {
|
|
|
|
this.semver = new plugins.semver.SemVer(semVerStringArg);
|
|
|
|
this.versionString = this.semver.version;
|
2017-08-17 14:15:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 15:42:34 +00:00
|
|
|
public get major() {
|
2018-09-02 10:26:04 +00:00
|
|
|
return this.semver.major;
|
2017-08-17 14:15:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 15:42:34 +00:00
|
|
|
public get minor() {
|
2018-09-02 10:26:04 +00:00
|
|
|
return this.semver.minor;
|
2017-08-17 14:15:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 15:42:34 +00:00
|
|
|
public get patch() {
|
2018-09-02 10:26:04 +00:00
|
|
|
return this.semver.patch;
|
2017-08-17 14:15:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 15:42:34 +00:00
|
|
|
public greaterThan(smartVersionArg: SmartVersion) {
|
2018-09-02 10:26:04 +00:00
|
|
|
return this.greaterThanString(smartVersionArg.versionString);
|
2017-08-18 10:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compares the version of this against a string
|
|
|
|
*/
|
2019-09-11 15:42:34 +00:00
|
|
|
public greaterThanString(versionStringArg) {
|
2018-09-02 10:26:04 +00:00
|
|
|
return plugins.semver.gt(this.versionString, versionStringArg);
|
2017-08-18 08:58:00 +00:00
|
|
|
}
|
|
|
|
|
2019-09-11 15:42:34 +00:00
|
|
|
public lessThan(smartVersionArg: SmartVersion) {
|
2018-09-02 10:26:04 +00:00
|
|
|
return this.lessThanString(smartVersionArg.versionString);
|
2017-08-18 10:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compares the version of this against a string
|
|
|
|
*/
|
2019-09-11 15:42:34 +00:00
|
|
|
public lessThanString(versionStringArg) {
|
2018-09-02 10:26:04 +00:00
|
|
|
return plugins.semver.lt(this.versionString, versionStringArg);
|
2017-08-18 08:58:00 +00:00
|
|
|
}
|
2017-08-17 14:15:47 +00:00
|
|
|
}
|