89 lines
8.5 KiB
JavaScript
89 lines
8.5 KiB
JavaScript
"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) {
|
|
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;
|
|
try {
|
|
npmPackage = (yield npmRegistry.search({ name: npmnameArg, boostExact: true }))[0];
|
|
}
|
|
catch (err) {
|
|
plugins.beautylog.warn('failed to retrieve package information...');
|
|
return null;
|
|
}
|
|
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();
|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