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() {
|
2017-10-07 11:34:36 +00:00
|
|
|
this.kvStore = new plugins.npmextra.KeyValueStore('custom', 'global_smartupdate');
|
2017-08-15 17:29:18 +00:00
|
|
|
}
|
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);
|
2017-09-11 12:13:37 +00:00
|
|
|
if (!npmPackage) {
|
2017-09-13 15:42:19 +00:00
|
|
|
plugins.beautylog.warn('failed to retrieve package information...');
|
|
|
|
plugins.beautylog.info('npms.io might be down');
|
2017-09-11 12:13:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-16 16:54:23 +00:00
|
|
|
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) {
|
2017-09-11 12:13:37 +00:00
|
|
|
// TODO:
|
2017-08-16 16:54:23 +00:00
|
|
|
}
|
|
|
|
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();
|
2017-09-11 12:13:37 +00:00
|
|
|
let npmPackage;
|
2017-09-13 15:42:19 +00:00
|
|
|
npmPackage = (yield npmRegistry.search({ name: npmnameArg, boostExact: true }))[0];
|
2017-08-16 16:54:23 +00:00
|
|
|
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 = S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