Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
1431e439a0 | |||
907d655d11 | |||
e9452c6b3c | |||
004881ec9d | |||
b295f3d7e3 | |||
c8438069d3 | |||
af212b068d | |||
ed87cdb101 | |||
cb589f5863 | |||
fc41cb1403 | |||
fdef084c6b | |||
87dd7b6635 | |||
2899972e5b | |||
2a9d678a68 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@ -1,137 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- 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
|
|
||||||
|
|
||||||
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
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
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
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
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:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartversion",
|
"gitrepo": "smartversion",
|
||||||
"shortDescription": "handle semver with ease",
|
"description": "handle semver with ease",
|
||||||
"npmPackagename": "@pushrocks/smartversion",
|
"npmPackagename": "@push.rocks/smartversion",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12797
package-lock.json
generated
12797
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -1,27 +1,27 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartversion",
|
"name": "@push.rocks/smartversion",
|
||||||
"version": "2.0.5",
|
"version": "3.0.4",
|
||||||
"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": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@git.zone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@git.zone/tsrun": "^1.2.32",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@git.zone/tstest": "^1.0.70",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@push.rocks/tapbundle": "^5.0.8",
|
||||||
"@types/node": "^14.14.41",
|
"@types/node": "^20.11.25"
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"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": [
|
||||||
@ -38,5 +38,13 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
]
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://gitlab.com/push.rocks/smartversion.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://gitlab.com/push.rocks/smartversion/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://gitlab.com/push.rocks/smartversion#readme"
|
||||||
}
|
}
|
||||||
|
5681
pnpm-lock.yaml
generated
Normal file
5681
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
readme.md
12
readme.md
@ -1,8 +1,8 @@
|
|||||||
# @pushrocks/smartversion
|
# @push.rocks/smartversion
|
||||||
handle semver with ease
|
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/@push.rocks/smartversion)
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartversion)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartversion)
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartversion)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartversion)
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartversion/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartversion/)
|
||||||
@ -13,14 +13,14 @@ Status Category | Status Badge
|
|||||||
-- | --
|
-- | --
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
npm | [](https://lossless.cloud)
|
npm | [](https://lossless.cloud)
|
||||||
Snyk | [](https://lossless.cloud)
|
Snyk | [](https://lossless.cloud)
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
Code Style | [](https://lossless.cloud)
|
Code Style | [](https://lossless.cloud)
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
36
test/test.both.ts
Normal file
36
test/test.both.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
import * as smartversion from '../ts/index.js';
|
||||||
|
|
||||||
|
tap.test('should create a valid SmartVersion', async () => {
|
||||||
|
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 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();
|
21
test/test.ts
21
test/test.ts
@ -1,21 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as smartversion from '../ts/index';
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
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.start();
|
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartversion',
|
||||||
|
version: '3.0.4',
|
||||||
|
description: 'handle semver with ease'
|
||||||
|
}
|
80
ts/index.ts
80
ts/index.ts
@ -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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
import * as semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
export { semver };
|
export { semver };
|
||||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user