Compare commits

14 Commits

Author SHA1 Message Date
284f4753e0 1.0.27 2019-09-06 13:58:18 +02:00
335e9160a6 fix(core): update 2019-09-06 13:58:17 +02:00
94c22b65e5 1.0.26 2019-09-06 13:39:40 +02:00
f1d07f968d fix(core): update 2019-09-06 13:39:39 +02:00
ac53d801a6 1.0.25 2019-09-05 17:40:41 +02:00
a75bb09d3f fix(core): update 2019-09-05 17:40:41 +02:00
01f70cf1a4 1.0.24 2019-09-04 16:38:06 +02:00
f9fccd2dff fix(core): update 2019-09-04 16:38:06 +02:00
3fb0203bae 1.0.23 2019-09-04 16:27:43 +02:00
5e7a5f26d4 fix(core): update 2019-09-04 16:27:42 +02:00
51c0cdcd13 1.0.22 2018-11-08 09:54:09 +01:00
1622a30e05 update 2018-11-08 09:54:06 +01:00
429a8d1098 1.0.21 2018-09-02 12:41:06 +02:00
7bfdb8db5e fix(dependencies): update to latest versions 2018-09-02 12:41:06 +02:00
16 changed files with 1542 additions and 626 deletions

19
.gitignore vendored
View File

@ -1,5 +1,22 @@
.nogit/
node_modules/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,5 +1,5 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -36,44 +37,35 @@ snyk:
# ====================
# 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:
stage: test
script:
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci node install lts
- npmci npm publish
only:
- tags
@ -86,19 +78,11 @@ release:
# ====================
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 install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
@ -114,12 +98,15 @@ trigger:
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- 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:
- docker
- notpriv
@ -130,13 +117,3 @@ pages:
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
allow_failure: true

8
dist/index.d.ts vendored
View File

@ -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
View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsaURBQWlEO0FBRWpELHlDQUFzQztBQVV0QztJQUFBO1FBQ0UsWUFBTyxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUMsUUFBUSxFQUFFLG9CQUFvQixDQUFDLENBQUM7SUFzRi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UFJLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxFQUFFLElBQUksZUFBZSxFQUFFO29CQUN0QyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyw2QkFBNkIsQ0FBQyxDQUFDO29CQUNyRCxPQUFPLENBQUMsU0FBUyxDQUFDLE9BQU8sQ0FBQyxlQUFlLENBQUMsQ0FBQztpQkFDNUM7Z0JBQ0QsT0FBTyxJQUFJLENBQUM7YUFDYjtRQUNILENBQUM7S0FBQTtDQUNGO0FBdkZELGtDQXVGQztBQUNVLFFBQUEsZUFBZSxHQUFHLElBQUksV0FBVyxFQUFFLENBQUMifQ==

View File

@ -1,8 +0,0 @@
import * as beautylog from 'beautylog';
import * as beautycolor from '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 };

View File

@ -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==

View File

@ -1,33 +0,0 @@
# smartupdate
update your tools in a smart way
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartupdate)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartupdate)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartupdate)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartupdate/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartupdate/badges/master/build.svg)](https://GitLab.com/pushrocks/smartupdate/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartupdate/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartupdate/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartupdate.svg)](https://www.npmjs.com/package/smartupdate)
[![Dependency Status](https://david-dm.org/pushrocks/smartupdate.svg)](https://david-dm.org/pushrocks/smartupdate)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartupdate/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartupdate/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartupdate/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartupdate)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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 | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | 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)

View File

@ -5,5 +5,15 @@
},
"npmts": {
"coverageTreshold": 50
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartupdate",
"shortDescription": "update your tools in a smart way",
"npmPackagename": "@pushrocks/smartupdate",
"license": "MIT"
}
}
}

1589
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartupdate",
"version": "1.0.20",
"version": "1.0.27",
"private": false,
"description": "update your tools in a smart way",
"main": "dist/index.js",
@ -12,19 +12,32 @@
"build": "(tsbuild)"
},
"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.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.4",
"tslint": "^5.19.0",
"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.5",
"@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartnpm": "^1.0.12",
"@pushrocks/smartopen": "^1.0.22",
"@pushrocks/smarttime": "^3.0.12",
"@pushrocks/smartversion": "^2.0.0"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

View File

@ -1,25 +1,20 @@
# smartupdate
# @pushrocks/smartupdate
update your tools in a smart way
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartupdate)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartupdate)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartupdate)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](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
[![build status](https://GitLab.com/pushrocks/smartupdate/badges/master/build.svg)](https://GitLab.com/pushrocks/smartupdate/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartupdate/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartupdate/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartupdate.svg)](https://www.npmjs.com/package/smartupdate)
[![Dependency Status](https://david-dm.org/pushrocks/smartupdate.svg)](https://david-dm.org/pushrocks/smartupdate)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartupdate/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartupdate/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartupdate/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartupdate)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![build status](https://gitlab.com/pushrocks/smartupdate/badges/master/build.svg)](https://gitlab.com/pushrocks/smartupdate/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartupdate/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartupdate/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartupdate.svg)](https://www.npmjs.com/package/@pushrocks/smartupdate)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartupdate/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartupdate)
[![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/)
## Usage
@ -45,3 +40,10 @@ For further information read the linked docs at the top of this README.
> | 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)
For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,12 +1,14 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartupdate from '../ts/index';
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();

View File

@ -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';

View File

@ -0,0 +1,111 @@
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 {
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) {
plugins.smartlog.defaultLogger.log('warn', 'failed to retrieve package information...');
plugins.smartlog.defaultLogger.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 {
plugins.smartlog.defaultLogger.log(
'warn',
`There is a newer version of ${npmPackage.name} available on npm.`
);
plugins.smartlog.defaultLogger.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;
}
}
}

View File

@ -5,6 +5,6 @@ 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 };

View File

@ -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"
}