smartupdate/dist/index.js

75 lines
7.3 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* () {
let result = yield this.kvStore.readKey(npmnameArg);
let timeStamp = new smarttime_1.TimeStamp();
// the newData to write
let newData = {
lastCheck: timeStamp.milliSeconds,
latestVersion: 'x.x.x',
performedUpgrade: false
};
if (result) {
let lastCheckTimeStamp = smarttime_1.TimeStamp.fromMilliSeconds(result.lastCheck);
let compareTime = plugins.smarttime.getMilliSecondsFromUnits({ hours: 1 });
2017-08-16 16:54:23 +00:00
if (!lastCheckTimeStamp.isOlderThan(timeStamp, compareTime)) {
2017-08-18 10:52:24 +00:00
plugins.beautylog.log(`smartupdate: next check in : ` +
`${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-18 10:52:24 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBp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