smartupdate/dist/index.js

68 lines
6.0 KiB
JavaScript
Raw Permalink 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-16 16:54:23 +00:00
check(npmnameArg, compareVersion) {
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({ days: 1 });
if (!lastCheckTimeStamp.isOlderThan(timeStamp, compareTime)) {
plugins.beautylog.log('not checking for new version since this has been done already for today');
return;
}
}
let npmPackage = yield this.getNpmPackageFromRegistry(npmnameArg);
newData.latestVersion = npmPackage.version;
let upgradeBool = yield this.checkIfUpgrade(npmPackage, compareVersion);
if (upgradeBool) {
}
this.kvStore.writeKey(npmnameArg, newData);
});
}
getNpmPackageFromRegistry(npmnameArg) {
return __awaiter(this, void 0, void 0, function* () {
plugins.beautylog.log(`checking for newer version of ${npmnameArg}...`);
let npmRegistry = new plugins.smartnpm.NpmRegistry();
let npmPackage = (yield npmRegistry.search({ name: npmnameArg, boostExact: true }))[0];
return npmPackage;
});
}
checkIfUpgrade(npmPackage, versionArg) {
return __awaiter(this, void 0, void 0, function* () {
if (npmPackage.version === versionArg) {
plugins.beautylog.ok(`You are running the latest version of ${npmPackage.name}`);
return false;
}
else {
plugins.beautylog.warn(`There is a newer version of ${npmPackage.name} available on npm.`);
plugins.beautylog.info(`Your version: ${versionArg} | version on npm: ${npmPackage.version}`);
plugins.beautylog.warn(`!!! You should upgrade!!!`);
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();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsaURBQWdEO0FBRWhELHlDQUFxQztBQVVyQztJQUFBO1FBQ0UsWUFBTyxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUMsUUFBUSxFQUFFLG9CQUFvQixDQUFDLENBQUE7SUErQzlFLENBQUM7SUE3Q08sS0FBSyxDQUFFLFVBQWtCLEVBQUUsY0FBc0I7O1lBQ3JELElBQUksTUFBTSxHQUFpQixNQUFNLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1lBQ2pFLElBQUksU0FBUyxHQUFHLElBQUkscUJBQVMsRUFBRSxDQUFBO1lBRS9CLHVCQUF1QjtZQUN2QixJQUFJLE9BQU8sR0FBRztnQkFDWixTQUFTLEVBQUUsU0FBUyxDQUFDLFlBQVk7Z0JBQ2pDLGFBQWEsRUFBRSxPQUFPO2dCQUN0QixnQkFBZ0IsRUFBRSxLQUFLO2FBQ3hCLEN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