12 Commits

Author SHA1 Message Date
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
10 changed files with 12477 additions and 1193 deletions

4
.gitignore vendored
View File

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

View File

@ -4,7 +4,7 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
@ -19,20 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk - npmci command npm install --production --ignore-scripts
- npmci command npm install --ignore-scripts - npmci command npm config set registry https://registry.npmjs.org
- npmci command snyk test - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - 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 # test stage
@ -48,7 +63,6 @@ testStable:
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -60,7 +74,6 @@ testBuild:
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -70,6 +83,7 @@ release:
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
@ -79,11 +93,15 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless
- docker - docker
- priv - priv
@ -94,20 +112,20 @@ trigger:
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: 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": { "npmci": {
"globalNpmTools": [], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"npmts": {
"coverageTreshold": 60
},
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smartversion", "gitrepo": "smartversion",
"shortDescription": "handle semver with easy", "shortDescription": "handle semver with ease",
"npmPackagename": "@pushrocks/smartversion", "npmPackagename": "@pushrocks/smartversion",
"license": "MIT" "license": "MIT"
} }

13747
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,5 +1,5 @@
# @pushrocks/smartversion # @pushrocks/smartversion
handle semver with easy handle semver with ease
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartversion) * [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/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartversion/)
## Status for master ## 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) Status Category | Status Badge
[![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) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartversion/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartversion/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartversion)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) 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 ## Usage
Use TypeScript for best in class instellisense. 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) ## Contribution
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![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. For further information read the linked docs at the top of this readme.

View File

@ -1,13 +1,9 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartversion from '../ts/index'; import * as smartversion from '../ts/index';
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).to.be.instanceof(smartversion.SmartVersion);
});
tap.test('should correctly classify greater and less than', async () => {
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(localSmartVersion.greaterThanString('4.0.0')).to.be.false; expect(localSmartVersion.greaterThanString('4.0.0')).to.be.false;
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
@ -18,4 +14,17 @@ tap.test('should correctly classify greater and less than', async () => {
expect(localSmartVersion.lessThanString('v3.0.0')).to.be.false; 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).to.be.instanceof(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).to.equal('4.7.5');
});
tap.start(); tap.start();

View File

@ -1,11 +1,14 @@
import * as plugins from './smartversion.plugins'; import * as plugins from './smartversion.plugins';
import { SemVer } from 'semver';
export class SmartVersion { export class SmartVersion {
semver: SemVer; public static fromFuzzyString(fuzzyString): SmartVersion {
versionString: string; return new SmartVersion(plugins.semver.minVersion(fuzzyString).version, fuzzyString);
update = { }
public originalVersionString: string;
public semver: plugins.semver.SemVer;
public versionString: string;
public update = {
patch: () => { patch: () => {
this.semver.patch = this.semver.patch + 1; this.semver.patch = this.semver.patch + 1;
}, },
@ -14,45 +17,66 @@ export class SmartVersion {
}, },
major: () => { major: () => {
this.semver.major = this.semver.major + 1; 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; this.versionString = this.semver.version;
} }
get major() { public get major() {
return this.semver.major; return this.semver.major;
} }
get minor() { public get minor() {
return this.semver.minor; return this.semver.minor;
} }
get patch() { public get patch() {
return this.semver.patch; return this.semver.patch;
} }
greaterThan(smartVersionArg: SmartVersion) { public greaterThan(smartVersionArg: SmartVersion) {
return this.greaterThanString(smartVersionArg.versionString); return this.greaterThanString(smartVersionArg.versionString);
} }
/** /**
* compares the version of this against a string * compares the version of this against a string
*/ */
greaterThanString(versionStringArg) { public greaterThanString(versionStringArg) {
return plugins.semver.gt(this.versionString, versionStringArg); return plugins.semver.gt(this.versionString, versionStringArg);
} }
lessThan(smartVersionArg: SmartVersion) { public lessThan(smartVersionArg: SmartVersion) {
return this.lessThanString(smartVersionArg.versionString); return this.lessThanString(smartVersionArg.versionString);
} }
/** /**
* compares the version of this against a string * compares the version of this against a string
*/ */
lessThanString(versionStringArg) { public lessThanString(versionStringArg) {
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;
}
} }