14 Commits

Author SHA1 Message Date
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
2899972e5b 2.0.6 2021-04-26 03:44:42 +00:00
2a9d678a68 fix(core): update 2021-04-26 03:44:42 +00:00
4f984eda13 2.0.5 2021-04-25 08:52:39 +00:00
9d78a120a0 fix(core): update 2021-04-25 08:52:39 +00:00
bb8e7cb608 2.0.4 2019-09-11 17:42:34 +02:00
601cd37d88 fix(core): update 2019-09-11 17:42:34 +02:00
e364545d0e 2.0.3 2019-09-11 17:39:07 +02:00
070a168b12 fix(core): update 2019-09-11 17:39:07 +02:00
673ba27e71 2.0.2 2019-09-11 17:38:37 +02:00
8726ad5269 fix(core): update 2019-09-11 17:38:36 +02:00
11 changed files with 18044 additions and 1025 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -4,7 +4,7 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
key: '$CI_BUILD_STAGE'
stages:
- security
@ -19,20 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
snyk:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
- notpriv
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
@ -48,7 +63,6 @@ testStable:
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- priv
testBuild:
stage: test
@ -60,7 +74,6 @@ testBuild:
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
@ -70,6 +83,7 @@ release:
only:
- tags
tags:
- lossless
- docker
- notpriv
@ -79,11 +93,15 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
@ -94,20 +112,20 @@ trigger:
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,17 +1,15 @@
{
"npmci": {
"globalNpmTools": [],
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"npmts": {
"coverageTreshold": 60
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartversion",
"shortDescription": "handle semver with easy",
"shortDescription": "handle semver with ease",
"npmPackagename": "@pushrocks/smartversion",
"license": "MIT"
}

18822
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,43 @@
{
"name": "@pushrocks/smartversion",
"version": "2.0.1",
"version": "3.0.0",
"private": false,
"description": "handle semver with easy",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"description": "handle semver with ease",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.5"
"@gitzone/tsbuild": "^2.1.61",
"@gitzone/tsrun": "^1.2.32",
"@gitzone/tstest": "^1.0.70",
"@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^17.0.27",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@types/semver": "^6.0.2",
"semver": "^6.3.0"
"@types/semver": "^7.3.9",
"semver": "^7.3.5"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -1,5 +1,5 @@
# @pushrocks/smartversion
handle semver with easy
handle semver with ease
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartversion)
@ -8,24 +8,29 @@ handle semver with easy
* [docs (typedoc)](https://pushrocks.gitlab.io/smartversion/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartversion/badges/master/build.svg)](https://gitlab.com/pushrocks/smartversion/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartversion/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartversion/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartversion.svg)](https://www.npmjs.com/package/@pushrocks/smartversion)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartversion/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartversion)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartversion/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartversion/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartversion)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartversion)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartversion)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartversion)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartversion)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
## Contribution
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.

View File

@ -1,21 +1,36 @@
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 () => {
localSmartVersion = new smartversion.SmartVersion('3.2.1');
expect(localSmartVersion).to.be.instanceof(smartversion.SmartVersion);
const localSmartVersion = new smartversion.SmartVersion('3.2.1');
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 () => {
// tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.greaterThanString('4.0.0')).to.be.false;
// tslint:disable-next-line:no-unused-expression
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');
expect(localSmartVersion).toBeInstanceOf(smartversion.SmartVersion);
console.log(localSmartVersion.versionString);
});
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();

View File

@ -1,58 +1,87 @@
import * as plugins from './smartversion.plugins';
import { SemVer } from 'semver';
import * as plugins from './smartversion.plugins.js';
export class SmartVersion {
semver: SemVer;
versionString: string;
update = {
patch: () => {
this.semver.patch = this.semver.patch + 1;
},
minor: () => {
this.semver.minor = this.semver.minor + 1;
},
major: () => {
this.semver.major = this.semver.major + 1;
public static fromFuzzyString(fuzzyString: string): SmartVersion {
return new SmartVersion(plugins.semver.minVersion(fuzzyString).version, fuzzyString);
}
public originalVersionString: string;
public semver: plugins.semver.SemVer;
public get versionString(): string {
return this.semver.version;
};
constructor(semVerStringArg: string) {
constructor(semVerStringArg: string, originalStringArg?: string) {
this.originalVersionString = originalStringArg;
this.semver = new plugins.semver.SemVer(semVerStringArg);
this.versionString = this.semver.version;
}
get major() {
public get major() {
return this.semver.major;
}
get minor() {
public get minor() {
return this.semver.minor;
}
get patch() {
public get patch() {
return this.semver.patch;
}
greaterThan(smartVersionArg: SmartVersion) {
public greaterThan(smartVersionArg: SmartVersion) {
return this.greaterThanString(smartVersionArg.versionString);
}
/**
* compares the version of this against a string
*/
greaterThanString(versionStringArg) {
public greaterThanString(versionStringArg: string) {
return plugins.semver.gt(this.versionString, versionStringArg);
}
lessThan(smartVersionArg: SmartVersion) {
public lessThan(smartVersionArg: SmartVersion) {
return this.lessThanString(smartVersionArg.versionString);
}
/**
* compares the version of this against a string
*/
lessThanString(versionStringArg) {
public lessThanString(versionStringArg: string) {
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}.${this.semver.patch}`);
return newInstance;
}
public getNewMajorVersion() {
const newInstance = new SmartVersion(`${this.semver.major + 1}.${this.semver.minor}.${this.semver.patch}`);
return newInstance;
}
}

View File

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