UNPKG

@codesnippets/codesnippets

Version:
40 lines (39 loc) 1.36 kB
"use strict"; exports.__esModule = true; exports.isUpToDateSync = exports.isUpToDate = void 0; var fs = require('fs'); var path = require('path'); var request = require('request'); var semver = require('semver'); var syncRequest = require('sync-request'); var versionLockPath = path.resolve(path.join(__dirname, '../snippets.lock')); var webLockPath = 'https://raw.githubusercontent.com/trimorphdev/codesnippets/master/snippets.lock'; /** * Sends whether or not the current snippet installation is up-to-date to the callback. * @param callback the callback */ function isUpToDate(callback) { var fileRaw = fs.readFileSync(versionLockPath); var data = fileRaw.toString(); request(webLockPath, function (err, res, body) { if (err) return callback(err, null); if (semver.gt(body, data)) return callback(null, true); callback(null, false); }); } exports.isUpToDate = isUpToDate; /** * Returns whether or not the current lockfile is up to date. * @returns the result */ function isUpToDateSync() { var fileRaw = fs.readFileSync(versionLockPath); var data = fileRaw.toString(); var res = syncRequest('GET', webLockPath); if (semver.gt(res.body.toString(), data)) return true; return false; } exports.isUpToDateSync = isUpToDateSync;