8 Commits

Author SHA1 Message Date
b295f3d7e3 3.0.2 2022-04-28 12:20:09 +02:00
c8438069d3 fix(core): update 2022-04-28 12:20:09 +02:00
af212b068d 3.0.1 2022-04-26 16:03:30 +02:00
ed87cdb101 fix(core): update 2022-04-26 16:03:30 +02:00
cb589f5863 3.0.0 2022-04-26 14:44:53 +02:00
fc41cb1403 BREAKING CHANGE(core): update 2022-04-26 14:44:53 +02:00
fdef084c6b 2.0.7 2021-04-26 07:16:27 +00:00
87dd7b6635 fix(core): update 2021-04-26 07:16:26 +00:00
6 changed files with 14659 additions and 8867 deletions

23335
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
{ {
"name": "@pushrocks/smartversion", "name": "@pushrocks/smartversion",
"version": "2.0.6", "version": "3.0.2",
"private": false, "private": false,
"description": "handle semver with ease", "description": "handle semver with ease",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
@ -12,16 +13,16 @@
"build": "(tsbuild --web)" "build": "(tsbuild --web)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.25", "@gitzone/tsbuild": "^2.1.61",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.32",
"@gitzone/tstest": "^1.0.52", "@gitzone/tstest": "^1.0.70",
"@pushrocks/tapbundle": "^3.2.14", "@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^14.14.41", "@types/node": "^17.0.27",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@types/semver": "^7.3.4", "@types/semver": "^7.3.9",
"semver": "^7.3.5" "semver": "^7.3.5"
}, },
"files": [ "files": [

View File

@ -1,21 +1,36 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartversion from '../ts/index'; import * as smartversion from '../ts/index.js';
let localSmartVersion: smartversion.SmartVersion;
tap.test('should create a valid SmartVersion', async () => { tap.test('should create a valid SmartVersion', async () => {
localSmartVersion = new smartversion.SmartVersion('3.2.1'); const localSmartVersion = new smartversion.SmartVersion('3.2.1');
expect(localSmartVersion).to.be.instanceof(smartversion.SmartVersion); expect(localSmartVersion).toBeInstanceOf(smartversion.SmartVersion);
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.greaterThanString('4.0.0')).toBeFalse();
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.greaterThanString('3.0.0')).toBeTrue();
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.lessThanString('v4.0.0')).toBeTrue();
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.lessThanString('v3.0.0')).toBeFalse();
}); });
tap.test('should correctly classify greater and less than', async () => { tap.test('should create a valid SmartVersion', async () => {
// tslint:disable-next-line:no-unused-expression const localSmartVersion = smartversion.SmartVersion.fromFuzzyString('4');
expect(localSmartVersion.greaterThanString('4.0.0')).to.be.false; expect(localSmartVersion).toBeInstanceOf(smartversion.SmartVersion);
// tslint:disable-next-line:no-unused-expression console.log(localSmartVersion.versionString);
expect(localSmartVersion.greaterThanString('3.0.0')).to.be.true;
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.lessThanString('v4.0.0')).to.be.true;
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.lessThanString('v3.0.0')).to.be.false;
}); });
tap.test('should create a valid SmartVersion', async () => {
const localSmartVersion = smartversion.SmartVersion.fromFuzzyString('4.x');
const bestMatch = localSmartVersion.getBestMatch(['4.0.1', '4.7.5', '4.3.0']);
console.log(bestMatch);
expect(bestMatch).toEqual('4.7.5');
});
tap.test('should create a patch version', async () => {
const versInstance = smartversion.SmartVersion.fromFuzzyString('1.2.3');
const newVersion = versInstance.getNewPatchVersion();
console.log(newVersion.versionString);
})
tap.start(); tap.start();

11
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,11 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const name: string = '@pushrocks/smartversion';
export const version: string = '3.0.2';
export const description: string = 'handle semver with ease'
export const commitinfo = {
name: '@pushrocks/smartversion',
version: '3.0.2',
description: 'handle semver with ease'
}

View File

@ -1,25 +1,19 @@
import * as plugins from './smartversion.plugins'; import * as plugins from './smartversion.plugins.js';
import { SemVer } from 'semver';
export class SmartVersion { export class SmartVersion {
public semver: SemVer; public static fromFuzzyString(fuzzyString: string): SmartVersion {
public versionString: string; return new SmartVersion(plugins.semver.minVersion(fuzzyString).version, fuzzyString);
public update = { }
patch: () => {
this.semver.patch = this.semver.patch + 1; public originalVersionString: string;
}, public semver: plugins.semver.SemVer;
minor: () => { public get versionString(): string {
this.semver.minor = this.semver.minor + 1; return this.semver.version;
},
major: () => {
this.semver.major = this.semver.major + 1;
},
}; };
constructor(semVerStringArg: string) { constructor(semVerStringArg: string, originalStringArg?: string) {
this.originalVersionString = originalStringArg;
this.semver = new plugins.semver.SemVer(semVerStringArg); this.semver = new plugins.semver.SemVer(semVerStringArg);
this.versionString = this.semver.version;
} }
public get major() { public get major() {
@ -41,7 +35,7 @@ export class SmartVersion {
/** /**
* compares the version of this against a string * compares the version of this against a string
*/ */
public greaterThanString(versionStringArg) { public greaterThanString(versionStringArg: string) {
return plugins.semver.gt(this.versionString, versionStringArg); return plugins.semver.gt(this.versionString, versionStringArg);
} }
@ -52,7 +46,55 @@ export class SmartVersion {
/** /**
* compares the version of this against a string * compares the version of this against a string
*/ */
public lessThanString(versionStringArg) { public lessThanString(versionStringArg: string) {
return plugins.semver.lt(this.versionString, versionStringArg); return plugins.semver.lt(this.versionString, versionStringArg);
} }
/**
* tries to get the best match from a range of available versions
*/
public getBestMatch(availableVersions: string[]): string {
let bestMatchingVersion: string;
for (const versionArg of availableVersions) {
if (!plugins.semver.satisfies(versionArg, this.originalVersionString)) {
continue;
}
if(!bestMatchingVersion) {
bestMatchingVersion = versionArg;
} else {
if (plugins.semver.lt(bestMatchingVersion, versionArg)) {
bestMatchingVersion = versionArg;
}
}
}
return bestMatchingVersion;
}
public getNewPatchVersion() {
const newInstance = new SmartVersion(`${this.semver.major}.${this.semver.minor}.${this.semver.patch + 1}`);
return newInstance;
}
public getNewMinorVersion() {
const newInstance = new SmartVersion(`${this.semver.major}.${this.semver.minor + 1}.${0}`);
return newInstance;
}
public getNewMajorVersion() {
const newInstance = new SmartVersion(`${this.semver.major + 1}.${0}.${0}`);
return newInstance;
}
public getNewVersion(typeArg: 'patch' | 'minor' | 'major') {
switch (typeArg) {
case 'patch':
return this.getNewPatchVersion();
case 'minor':
return this.getNewMinorVersion();
case 'major':
return this.getNewMajorVersion();
default:
throw new Error('unknown new version type.');
}
}
} }

View File

@ -1,3 +1,3 @@
import * as semver from 'semver'; import semver from 'semver';
export { semver }; export { semver };