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;
|
2017-08-20 09:28:11 +00:00
|
|
|
plugins.beautylog.log(`next update check in less than ${Math.floor(nextCheckInMinutes) + 1} minute(s): ` +
|
2017-08-18 10:52:11 +00:00
|
|
|
`${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;
|
|
|
|
});
|
|
|
|
}
|
2017-08-18 10:52:11 +00:00
|
|
|
checkIfUpgrade(npmPackage, localVersionStringArg, changelogUrlArg) {
|
2017-08-16 16:54:23 +00:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2017-08-18 10:52:11 +00:00
|
|
|
// 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.`);
|
2017-08-18 10:52:11 +00:00
|
|
|
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-20 09:28:11 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsaURBQWdEO0FBRWhELHlDQUFxQztBQVVyQztJQUFBO1FBQ0UsWUFBTyxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUM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