78 lines
7.9 KiB
JavaScript
78 lines
7.9 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(`smartupdate: next check in ${Math.round(nextCheckInMinutes)} minutes: ` +
|
|
`${plugins.beautycolor.coloredString(`${npmnameArg} has already been checked within the last hour.`, 'pink')}`);
|
|
return;
|
|
}
|
|
}
|
|
let npmPackage = yield this.getNpmPackageFromRegistry(npmnameArg);
|
|
newData.latestVersion = npmPackage.version;
|
|
let upgradeBool = yield this.checkIfUpgrade(npmPackage, compareVersion, changelogUrlArg);
|
|
if (upgradeBool) {
|
|
}
|
|
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 = (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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJ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