UNPKG

@codesnippets/codesnippets

Version:
42 lines (33 loc) 1.2 kB
const fs = require('fs'); const path = require('path'); const request = require('request'); const semver = require('semver'); const syncRequest = require('sync-request'); const versionLockPath = path.resolve(path.join(__dirname, '../snippets.lock')); const 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 */ export function isUpToDate(callback: (err: any, res: any) => any) { const fileRaw = fs.readFileSync(versionLockPath); const data = fileRaw.toString(); request(webLockPath, (err, res, body) => { if (err) return callback(err, null); if (semver.gt(body, data)) return callback(null, true); callback(null, false); }); } /** * Returns whether or not the current lockfile is up to date. * @returns the result */ export function isUpToDateSync(): boolean { const fileRaw = fs.readFileSync(versionLockPath); const data = fileRaw.toString(); let res = syncRequest('GET', webLockPath); if(semver.gt(res.body.toString(), data)) return true; return false; }