smartupdate/dist/index.js

78 lines
7.9 KiB
JavaScript
Raw Normal View History

2017-08-15 17:29:18 +00:00
"use strict";
2017-08-16 16:54:23 +00:00
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());
});
};
2017-08-15 17:29:18 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartupdate.plugins");
2017-08-16 16:54:23 +00:00
const smarttime_1 = require("smarttime");
2017-08-15 17:29:18 +00:00
class SmartUpdate {
constructor() {
this.kvStore = new plugins.npmextra.KeyValueStore('custom', 'global:smartupdate');
}
2017-08-17 09:56:38 +00:00
check(npmnameArg, compareVersion, changelogUrlArg) {
2017-08-16 16:54:23 +00:00
return __awaiter(this, void 0, void 0, function* () {
// the newData to write
2017-08-19 22:09:26 +00:00
let timeStamp = new smarttime_1.TimeStamp();
2017-08-16 16:54:23 +00:00
let newData = {
lastCheck: timeStamp.milliSeconds,
latestVersion: 'x.x.x',
performedUpgrade: false
};
2017-08-19 22:09:26 +00:00
// the comparison data from the keyValue store
let result = yield this.kvStore.readKey(npmnameArg);
2017-08-16 16:54:23 +00:00
if (result) {
let lastCheckTimeStamp = smarttime_1.TimeStamp.fromMilliSeconds(result.lastCheck);
2017-08-19 22:45:45 +00:00
let tresholdTime = plugins.smarttime.getMilliSecondsFromUnits({ hours: 1 });
if (!lastCheckTimeStamp.isOlderThan(timeStamp, tresholdTime)) {
2017-08-19 10:32:24 +00:00
newData.lastCheck = lastCheckTimeStamp.milliSeconds;
2017-08-19 22:45:45 +00:00
let nextCheckInMinutes = (tresholdTime - (timeStamp.milliSeconds - lastCheckTimeStamp.milliSeconds)) / 60000;
plugins.beautylog.log(`smartupdate: next check in ${Math.round(nextCheckInMinutes)} minutes: ` +
`${plugins.beautycolor.coloredString(`${npmnameArg} has already been checked within the last hour.`, 'pink')}`);
2017-08-16 16:54:23 +00:00
return;
}
}
let npmPackage = yield this.getNpmPackageFromRegistry(npmnameArg);
newData.latestVersion = npmPackage.version;
2017-08-17 09:56:38 +00:00
let upgradeBool = yield this.checkIfUpgrade(npmPackage, compareVersion, changelogUrlArg);
2017-08-16 16:54:23 +00:00
if (upgradeBool) {
}
this.kvStore.writeKey(npmnameArg, newData);
});
}
getNpmPackageFromRegistry(npmnameArg) {
return __awaiter(this, void 0, void 0, function* () {
2017-08-16 21:28:12 +00:00
plugins.beautylog.log(`smartupdate: checking for newer version of ${plugins.beautycolor.coloredString(npmnameArg, 'pink')}...`);
2017-08-16 16:54:23 +00:00
let npmRegistry = new plugins.smartnpm.NpmRegistry();
let npmPackage = (yield npmRegistry.search({ name: npmnameArg, boostExact: true }))[0];
return npmPackage;
});
}
checkIfUpgrade(npmPackage, localVersionStringArg, changelogUrlArg) {
2017-08-16 16:54:23 +00:00
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);
2017-08-18 10:52:24 +00:00
if (!versionNpm.greaterThan(versionLocal)) {
2017-08-16 21:28:12 +00:00
plugins.beautylog.ok(`smartupdate: You are running the latest version of ${plugins.beautycolor.coloredString(npmPackage.name, 'pink')}`);
2017-08-16 16:54:23 +00:00
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}`);
2017-08-17 09:56:38 +00:00
if (!process.env.CI && changelogUrlArg) {
plugins.beautylog.log('trying to open changelog...');
plugins.smartopen.openUrl(changelogUrlArg);
}
2017-08-16 16:54:23 +00:00
return true;
}
});
2017-08-15 17:29:18 +00:00
}
}
2017-08-16 16:54:23 +00:00
exports.SmartUpdate = SmartUpdate;
exports.standardHandler = new SmartUpdate();
2017-08-19 22:45:45 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsaURBQWdEO0FBRWhELHlDQUFxQztBQVVyQztJQUFBO1FBQ0UsWUFBTyxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUMsUUFBUSxFQUFFLG9CQUFvQixDQUFDLENBQUE7SUFvRTlFLENBQUM7SUFsRU8sS0FBSyxDQUFFLFVBQWtCLEVBQUUsY0FBc0IsRUFBRSxlQUF3Qjs7WUFFL0UsdUJBQXVCO1lBQ3ZCLElBQUksU0FBUyxHQUFHLElBQUkscUJBQVMsRUFBRSxDQUFBO1lBQy9CLElBQUksT0FBTyxHQUFHO2dCQUNaLFNBQVMsRUFBRSxTQUFTLENBQUMsWUFBWTtnQkFDakMsYUFBYSxFQUFFLE9BQU87Z0JBQ3RCLGdCQUFnQixFQUFFLEtBQUs7YUFDeEIsQ0FBQTtZQUVELDhDQUE4QztZQUM5QyxJQUFJLE1BQU0sR0FBaUIsTUFBTSxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsQ0FBQTtZQUVqRSxFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO2dCQUNYLElBQUksa0JBQWtCLEdBQUcscUJBQVMsQ0FBQyxnQkFBZ0IsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLENBQUE7Z0JBQ3JFLElBQUksWUFBWSxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsd0JBQXdCLENBQUMsRUFBRSxLQUFLLEVBQUUs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