Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
cf894d9e82 | |||
1da4e08ed2 | |||
66546a8b17 | |||
3c3275ece5 | |||
d43fbe6de6 | |||
16fd8be8be | |||
297e65ebe5 | |||
a5c019419b | |||
815694dd8b | |||
083786795e | |||
284f4753e0 | |||
335e9160a6 | |||
94c22b65e5 | |||
f1d07f968d | |||
ac53d801a6 | |||
a75bb09d3f | |||
01f70cf1a4 | |||
f9fccd2dff | |||
3fb0203bae | |||
5e7a5f26d4 | |||
51c0cdcd13 | |||
1622a30e05 | |||
429a8d1098 | |||
7bfdb8db5e |
17
.gitignore
vendored
17
.gitignore
vendored
@ -1,5 +1,20 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
@ -18,109 +18,104 @@ stages:
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
audit:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm install -g snyk
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install legacy
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -128,15 +123,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
||||
windowsCompatibility:
|
||||
image: stefanscherer/node-windows:10-build-tools
|
||||
stage: metadata
|
||||
script:
|
||||
- npm install & npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- windows
|
||||
- public
|
||||
allow_failure: true
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal 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
26
.vscode/settings.json
vendored
Normal 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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
8
dist/index.d.ts
vendored
8
dist/index.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
import * as plugins from './smartupdate.plugins';
|
||||
export declare class SmartUpdate {
|
||||
kvStore: plugins.npmextra.KeyValueStore;
|
||||
check(npmnameArg: string, compareVersion: string, changelogUrlArg?: string): Promise<void>;
|
||||
private getNpmPackageFromRegistry(npmnameArg);
|
||||
private checkIfUpgrade(npmPackage, localVersionStringArg, changelogUrlArg?);
|
||||
}
|
||||
export declare let standardHandler: SmartUpdate;
|
85
dist/index.js
vendored
85
dist/index.js
vendored
@ -1,85 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugins = require("./smartupdate.plugins");
|
||||
const smarttime_1 = require("smarttime");
|
||||
class SmartUpdate {
|
||||
constructor() {
|
||||
this.kvStore = new plugins.npmextra.KeyValueStore('custom', 'global_smartupdate');
|
||||
}
|
||||
check(npmnameArg, compareVersion, changelogUrlArg) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// the newData to write
|
||||
let timeStamp = new smarttime_1.TimeStamp();
|
||||
let newData = {
|
||||
lastCheck: timeStamp.milliSeconds,
|
||||
latestVersion: 'x.x.x',
|
||||
performedUpgrade: false
|
||||
};
|
||||
// the comparison data from the keyValue store
|
||||
let result = yield this.kvStore.readKey(npmnameArg);
|
||||
if (result) {
|
||||
let lastCheckTimeStamp = smarttime_1.TimeStamp.fromMilliSeconds(result.lastCheck);
|
||||
let tresholdTime = plugins.smarttime.getMilliSecondsFromUnits({ hours: 1 });
|
||||
if (!lastCheckTimeStamp.isOlderThan(timeStamp, tresholdTime)) {
|
||||
newData.lastCheck = lastCheckTimeStamp.milliSeconds;
|
||||
let nextCheckInMinutes = (tresholdTime - (timeStamp.milliSeconds - lastCheckTimeStamp.milliSeconds)) / 60000;
|
||||
plugins.beautylog.log(`next update check in less than ${Math.floor(nextCheckInMinutes) + 1} minute(s): ` +
|
||||
`${plugins.beautycolor.coloredString(`${npmnameArg} has already been checked within the last hour.`, 'pink')}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let npmPackage = yield this.getNpmPackageFromRegistry(npmnameArg);
|
||||
if (!npmPackage) {
|
||||
plugins.beautylog.warn('failed to retrieve package information...');
|
||||
plugins.beautylog.info('npms.io might be down');
|
||||
return;
|
||||
}
|
||||
newData.latestVersion = npmPackage.version;
|
||||
let upgradeBool = yield this.checkIfUpgrade(npmPackage, compareVersion, changelogUrlArg);
|
||||
if (upgradeBool) {
|
||||
// TODO:
|
||||
}
|
||||
this.kvStore.writeKey(npmnameArg, newData);
|
||||
});
|
||||
}
|
||||
getNpmPackageFromRegistry(npmnameArg) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
plugins.beautylog.log(`smartupdate: checking for newer version of ${plugins.beautycolor.coloredString(npmnameArg, 'pink')}...`);
|
||||
let npmRegistry = new plugins.smartnpm.NpmRegistry();
|
||||
let npmPackage;
|
||||
npmPackage = (yield npmRegistry.search({ name: npmnameArg, boostExact: true }))[0];
|
||||
return npmPackage;
|
||||
});
|
||||
}
|
||||
checkIfUpgrade(npmPackage, localVersionStringArg, changelogUrlArg) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// create Version objects
|
||||
let versionNpm = new plugins.smartversion.SmartVersion(npmPackage.version);
|
||||
let versionLocal = new plugins.smartversion.SmartVersion(localVersionStringArg);
|
||||
if (!versionNpm.greaterThan(versionLocal)) {
|
||||
plugins.beautylog.ok(`smartupdate: You are running the latest version of ${plugins.beautycolor.coloredString(npmPackage.name, 'pink')}`);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
plugins.beautylog.warn(`There is a newer version of ${npmPackage.name} available on npm.`);
|
||||
plugins.beautylog.warn(`Your version: ${versionLocal.versionString} | version on npm: ${versionNpm.versionString}`);
|
||||
if (!process.env.CI && changelogUrlArg) {
|
||||
plugins.beautylog.log('trying to open changelog...');
|
||||
plugins.smartopen.openUrl(changelogUrlArg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.SmartUpdate = SmartUpdate;
|
||||
exports.standardHandler = new SmartUpdate();
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsaURBQWlEO0FBRWpELHlDQUFzQztBQVV0QztJQUFBO1FBQ0UsWUFBTyxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUMsUUFBUSxFQUFFLG9CQUFvQixDQUFDLENBQUM7SUFzRi9FLENBQUM7SUFwRk8sS0FBSyxDQUFDLFVBQWtCLEVBQUUsY0FBc0IsRUFBRSxlQUF3Qjs7WUFDOUUsdUJBQXVCO1lBQ3ZCLElBQUksU0FBUyxHQUFHLElBQUkscUJBQVMsRUFBRSxDQUFDO1lBQ2hDLElBQUksT0FBTyxHQUFHO2dCQUNaLFNBQVMsRUFBRSxTQUFTLENBQUMsWUFBWTtnQkFDakMsYUFBYSxFQUFFLE9BQU87Z0JBQ3RCLGdCQUFnQixFQUFFLEtBQUs7YUFDeEIsQ0FBQztZQUVGLDhDQUE4QztZQUM5QyxJQUFJLE1BQU0sR0FBaUIsTUFBTSxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQztZQUVsRSxJQUFJLE1BQU0sRUFBRTtnQkFDVixJQUFJLGtCQUFrQ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beautycolor';
|
||||
import * as npmextra from 'npmextra';
|
||||
import * as smartnpm from 'smartnpm';
|
||||
import * as smartopen from '@pushrocks/smartopen';
|
||||
import * as smarttime from 'smarttime';
|
||||
import * as smartversion from 'smartversion';
|
||||
export { beautylog, beautycolor, npmextra, smartnpm, smartopen, smarttime, smartversion };
|
17
dist/smartupdate.plugins.js
vendored
17
dist/smartupdate.plugins.js
vendored
@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const beautylog = require("beautylog");
|
||||
exports.beautylog = beautylog;
|
||||
const beautycolor = require("beautycolor");
|
||||
exports.beautycolor = beautycolor;
|
||||
const npmextra = require("npmextra");
|
||||
exports.npmextra = npmextra;
|
||||
const smartnpm = require("smartnpm");
|
||||
exports.smartnpm = smartnpm;
|
||||
const smartopen = require("@pushrocks/smartopen");
|
||||
exports.smartopen = smartopen;
|
||||
const smarttime = require("smarttime");
|
||||
exports.smarttime = smarttime;
|
||||
const smartversion = require("smartversion");
|
||||
exports.smartversion = smartversion;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1cGRhdGUucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0dXBkYXRlLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx1Q0FBdUM7QUFROUIsOEJBQVM7QUFQbEIsMkNBQTJDO0FBT3ZCLGtDQUFXO0FBTi9CLHFDQUFxQztBQU1KLDRCQUFRO0FBTHpDLHFDQUFxQztBQUtNLDRCQUFRO0FBSm5ELGtEQUFrRDtBQUlHLDhCQUFTO0FBSDlELHVDQUF1QztBQUd5Qiw4QkFBUztBQUZ6RSw2Q0FBNkM7QUFFOEIsb0NBQVkifQ==
|
@ -1,33 +0,0 @@
|
||||
# smartupdate
|
||||
|
||||
update your tools in a smart way
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/smartupdate)
|
||||
[](https://GitLab.com/pushrocks/smartupdate)
|
||||
[](https://github.com/pushrocks/smartupdate)
|
||||
[](https://pushrocks.gitlab.io/smartupdate/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartupdate/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartupdate/commits/master)
|
||||
[](https://www.npmjs.com/package/smartupdate)
|
||||
[](https://david-dm.org/pushrocks/smartupdate)
|
||||
[](https://www.bithound.io/github/pushrocks/smartupdate/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartupdate)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## 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)
|
||||
|
||||
[](https://push.rocks)
|
@ -3,7 +3,15 @@
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"npmts": {
|
||||
"coverageTreshold": 50
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartupdate",
|
||||
"shortDescription": "update your tools in a smart way",
|
||||
"npmPackagename": "@pushrocks/smartupdate",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
22350
package-lock.json
generated
22350
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@ -1,30 +1,44 @@
|
||||
{
|
||||
"name": "@pushrocks/smartupdate",
|
||||
"version": "1.0.20",
|
||||
"version": "2.0.0",
|
||||
"private": false,
|
||||
"description": "update your tools in a smart way",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsrun": "^1.1.12",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.5",
|
||||
"@types/node": "^10.9.4"
|
||||
"@gitzone/tsbuild": "^2.1.61",
|
||||
"@gitzone/tsrun": "^1.2.32",
|
||||
"@gitzone/tstest": "^1.0.70",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^17.0.23",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/consolecolor": "^2.0.1",
|
||||
"@pushrocks/npmextra": "^3.0.1",
|
||||
"@pushrocks/smartlog": "^2.0.1",
|
||||
"@pushrocks/smartnpm": "^1.0.8",
|
||||
"@pushrocks/smartopen": "^1.0.8",
|
||||
"@pushrocks/smarttime": "^2.0.2",
|
||||
"smartversion": "^1.0.3"
|
||||
}
|
||||
"@pushrocks/npmextra": "^3.0.9",
|
||||
"@pushrocks/smartnpm": "^2.0.0",
|
||||
"@pushrocks/smartopen": "^2.0.0",
|
||||
"@pushrocks/smarttime": "^3.0.45",
|
||||
"@pushrocks/smartversion": "^2.0.7"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
46
readme.md
46
readme.md
@ -1,25 +1,27 @@
|
||||
# smartupdate
|
||||
|
||||
# @pushrocks/smartupdate
|
||||
update your tools in a smart way
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/smartupdate)
|
||||
[](https://GitLab.com/pushrocks/smartupdate)
|
||||
[](https://github.com/pushrocks/smartupdate)
|
||||
[](https://pushrocks.gitlab.io/smartupdate/)
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartupdate)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartupdate)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartupdate)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartupdate/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartupdate/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartupdate/commits/master)
|
||||
[](https://www.npmjs.com/package/smartupdate)
|
||||
[](https://david-dm.org/pushrocks/smartupdate)
|
||||
[](https://www.bithound.io/github/pushrocks/smartupdate/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartupdate)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
@ -39,9 +41,13 @@ await smartupdate.standardHandler.check(
|
||||
);
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
## Contribution
|
||||
|
||||
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.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://push.rocks)
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
14
test/test.ts
14
test/test.ts
@ -1,12 +1,14 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartupdate from '../ts/index';
|
||||
import * as smartupdate from '../ts/index.js';
|
||||
|
||||
let testSmartUpdate: smartupdate.SmartUpdate;
|
||||
|
||||
tap.test('should create an instance of SmartUpdate', async () => {
|
||||
testSmartUpdate = new smartupdate.SmartUpdate();
|
||||
});
|
||||
|
||||
tap.test('should check for a npm module', async () => {
|
||||
await smartupdate.standardHandler.check(
|
||||
'lodash',
|
||||
'1.0.5',
|
||||
'http://gitzone.gitlab.io/npmts/changelog.html'
|
||||
);
|
||||
await testSmartUpdate.check('lodash', '1.0.5');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
104
ts/index.ts
104
ts/index.ts
@ -1,103 +1 @@
|
||||
import * as plugins from './smartupdate.plugins';
|
||||
|
||||
import { TimeStamp } from '@pushrocks/smarttime';
|
||||
|
||||
interface ICacheStatus {
|
||||
lastCheck: number;
|
||||
latestVersion: string;
|
||||
performedUpgrade: boolean;
|
||||
}
|
||||
|
||||
import { KeyValueStore } from '@pushrocks/npmextra';
|
||||
|
||||
export class SmartUpdate {
|
||||
kvStore = new plugins.npmextra.KeyValueStore('custom', 'global_smartupdate');
|
||||
|
||||
async check(npmnameArg: string, compareVersion: string, changelogUrlArg?: string) {
|
||||
// the newData to write
|
||||
let timeStamp = new TimeStamp();
|
||||
let newData = {
|
||||
lastCheck: timeStamp.milliSeconds,
|
||||
latestVersion: 'x.x.x',
|
||||
performedUpgrade: false
|
||||
};
|
||||
|
||||
// the comparison data from the keyValue store
|
||||
let result: ICacheStatus = await this.kvStore.readKey(npmnameArg);
|
||||
|
||||
if (result) {
|
||||
let lastCheckTimeStamp = TimeStamp.fromMilliSeconds(result.lastCheck);
|
||||
let tresholdTime = plugins.smarttime.getMilliSecondsFromUnits({ hours: 1 });
|
||||
if (!lastCheckTimeStamp.isOlderThan(timeStamp, tresholdTime)) {
|
||||
newData.lastCheck = lastCheckTimeStamp.milliSeconds;
|
||||
let nextCheckInMinutes =
|
||||
(tresholdTime - (timeStamp.milliSeconds - lastCheckTimeStamp.milliSeconds)) / 60000;
|
||||
console.log(
|
||||
`next update check in less than ${Math.floor(nextCheckInMinutes) + 1} minute(s): ` +
|
||||
`${plugins.consolecolor.coloredString(
|
||||
`${npmnameArg} has already been checked within the last hour.`,
|
||||
'pink'
|
||||
)}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
let npmPackage = await this.getNpmPackageFromRegistry(npmnameArg);
|
||||
if (!npmPackage) {
|
||||
plugins.smartlog.defaultLogger.warn('failed to retrieve package information...');
|
||||
plugins.smartlog.defaultLogger.info('npms.io might be down');
|
||||
return;
|
||||
}
|
||||
newData.latestVersion = npmPackage.version;
|
||||
let upgradeBool = await this.checkIfUpgrade(npmPackage, compareVersion, changelogUrlArg);
|
||||
if (upgradeBool) {
|
||||
// TODO:
|
||||
}
|
||||
this.kvStore.writeKey(npmnameArg, newData);
|
||||
}
|
||||
|
||||
private async getNpmPackageFromRegistry(npmnameArg): Promise<plugins.smartnpm.NpmPackage> {
|
||||
console.log(
|
||||
`smartupdate: checking for newer version of ${plugins.consolecolor.coloredString(
|
||||
npmnameArg,
|
||||
'pink'
|
||||
)}...`
|
||||
);
|
||||
let npmRegistry = new plugins.smartnpm.NpmRegistry();
|
||||
let npmPackage: plugins.smartnpm.NpmPackage;
|
||||
npmPackage = (await npmRegistry.search({ name: npmnameArg, boostExact: true }))[0];
|
||||
return npmPackage;
|
||||
}
|
||||
|
||||
private async checkIfUpgrade(
|
||||
npmPackage: plugins.smartnpm.NpmPackage,
|
||||
localVersionStringArg: string,
|
||||
changelogUrlArg?: string
|
||||
) {
|
||||
// create Version objects
|
||||
let versionNpm = new plugins.smartversion.SmartVersion(npmPackage.version);
|
||||
let versionLocal = new plugins.smartversion.SmartVersion(localVersionStringArg);
|
||||
if (!versionNpm.greaterThan(versionLocal)) {
|
||||
console.log(
|
||||
`smartupdate: You are running the latest version of ${plugins.consolecolor.coloredString(
|
||||
npmPackage.name,
|
||||
'pink'
|
||||
)}`
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
plugins.smartlog.defaultLogger.warn(
|
||||
`There is a newer version of ${npmPackage.name} available on npm.`
|
||||
);
|
||||
plugins.smartlog.defaultLogger.warn(
|
||||
`Your version: ${versionLocal.versionString} | version on npm: ${versionNpm.versionString}`
|
||||
);
|
||||
if (!process.env.CI && changelogUrlArg) {
|
||||
console.log('trying to open changelog...');
|
||||
plugins.smartopen.openUrl(changelogUrlArg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
export let standardHandler = new SmartUpdate();
|
||||
export { SmartUpdate } from './smartupdate.classes.smartupdate.js';
|
||||
|
107
ts/smartupdate.classes.smartupdate.ts
Normal file
107
ts/smartupdate.classes.smartupdate.ts
Normal file
@ -0,0 +1,107 @@
|
||||
import * as plugins from './smartupdate.plugins.js';
|
||||
|
||||
import { TimeStamp } from '@pushrocks/smarttime';
|
||||
|
||||
interface ICacheStatus {
|
||||
lastCheck: number;
|
||||
latestVersion: string;
|
||||
performedUpgrade: boolean;
|
||||
}
|
||||
|
||||
import { KeyValueStore } from '@pushrocks/npmextra';
|
||||
|
||||
export class SmartUpdate {
|
||||
public npmRegistry: plugins.smartnpm.NpmRegistry;
|
||||
public kvStore = new plugins.npmextra.KeyValueStore('custom', 'global_smartupdate');
|
||||
|
||||
constructor(optionsArg: plugins.smartnpm.INpmRegistryConstructorOptions = {}) {
|
||||
this.npmRegistry = new plugins.smartnpm.NpmRegistry(optionsArg);
|
||||
}
|
||||
|
||||
public async checkForCli(npmnameArg: string, compareVersion: string, changelogUrlArg?: string) {
|
||||
// the newData to write
|
||||
const timeStamp = new TimeStamp();
|
||||
const newCacheData: ICacheStatus = {
|
||||
lastCheck: timeStamp.milliSeconds,
|
||||
latestVersion: 'x.x.x',
|
||||
performedUpgrade: false
|
||||
};
|
||||
|
||||
// the comparison data from the keyValue store
|
||||
const retrievedCacheData: ICacheStatus = await this.kvStore.readKey(npmnameArg);
|
||||
|
||||
if (retrievedCacheData) {
|
||||
const lastCheckTimeStamp = TimeStamp.fromMilliSeconds(retrievedCacheData.lastCheck);
|
||||
const tresholdTime = plugins.smarttime.getMilliSecondsFromUnits({ hours: 1 });
|
||||
if (!lastCheckTimeStamp.isOlderThan(timeStamp, tresholdTime)) {
|
||||
newCacheData.lastCheck = lastCheckTimeStamp.milliSeconds;
|
||||
const nextCheckInMinutes =
|
||||
(tresholdTime - (timeStamp.milliSeconds - lastCheckTimeStamp.milliSeconds)) / 60000;
|
||||
console.log(
|
||||
`next update check in less than ${Math.floor(nextCheckInMinutes) + 1} minute(s): ` +
|
||||
`${plugins.consolecolor.coloredString(
|
||||
`${npmnameArg} has already been checked within the last hour.`,
|
||||
'pink'
|
||||
)}`
|
||||
);
|
||||
return false; // don't upgrade if checked within reasonable time
|
||||
}
|
||||
}
|
||||
|
||||
const upgradeBool = await this.check(npmnameArg, compareVersion, changelogUrlArg);
|
||||
if (upgradeBool) {
|
||||
const npmPackage = await this.npmRegistry.getPackageInfo(npmnameArg);
|
||||
newCacheData.latestVersion = npmPackage.version;
|
||||
this.kvStore.writeKey(npmnameArg, newCacheData);
|
||||
}
|
||||
|
||||
return upgradeBool;
|
||||
}
|
||||
|
||||
private async getNpmPackageFromRegistry(npmnameArg): Promise<plugins.smartnpm.NpmPackage> {
|
||||
console.log(
|
||||
`smartupdate: checking for newer version of ${plugins.consolecolor.coloredString(
|
||||
npmnameArg,
|
||||
'pink'
|
||||
)}...`
|
||||
);
|
||||
const npmPackage = this.npmRegistry.getPackageInfo(npmnameArg);
|
||||
return npmPackage;
|
||||
}
|
||||
|
||||
public async check(
|
||||
npmPackageName: string,
|
||||
localVersionStringArg: string,
|
||||
changelogUrlArg?: string
|
||||
) {
|
||||
const npmPackage = await this.getNpmPackageFromRegistry(npmPackageName);
|
||||
if (!npmPackage) {
|
||||
console.log('warn: failed to retrieve package information...');
|
||||
console.log('info: is the registry down?');
|
||||
return;
|
||||
}
|
||||
|
||||
// create Version objects
|
||||
const versionNpm = new plugins.smartversion.SmartVersion(npmPackage.version);
|
||||
const versionLocal = new plugins.smartversion.SmartVersion(localVersionStringArg);
|
||||
if (!versionNpm.greaterThan(versionLocal)) {
|
||||
console.log(
|
||||
`smartupdate: You are running the latest version of ${plugins.consolecolor.coloredString(
|
||||
npmPackage.name,
|
||||
'pink'
|
||||
)}`
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
console.log(`warn: There is a newer version of ${npmPackage.name} available on npm.`);
|
||||
console.log(
|
||||
`warn: Your version: ${versionLocal.versionString} | version on npm: ${versionNpm.versionString}`
|
||||
);
|
||||
if (!process.env.CI && changelogUrlArg) {
|
||||
console.log('trying to open changelog...');
|
||||
plugins.smartopen.openUrl(changelogUrlArg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
smartlog.defaultLogger.enableConsole();
|
||||
import * as consolecolor from '@pushrocks/consolecolor';
|
||||
import * as npmextra from '@pushrocks/npmextra';
|
||||
import * as smartnpm from '@pushrocks/smartnpm';
|
||||
import * as smartopen from '@pushrocks/smartopen';
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
import * as smartversion from 'smartversion';
|
||||
import * as smartversion from '@pushrocks/smartversion';
|
||||
|
||||
export { smartlog, consolecolor, npmextra, smartnpm, smartopen, smarttime, smartversion };
|
||||
export { consolecolor, npmextra, smartnpm, smartopen, smarttime, smartversion };
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"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