UNPKG

hhurley

Version:

Tool to find lost security patches for Linux distributions.

82 lines (51 loc) 1.67 kB
/* Copyright IBM Research Emergent Solutions Jesús Pérez <jesusprubio@gmail.com> This code may only be used under the MIT license found at https://opensource.org/licenses/MIT. */ 'use strict'; // All common helpers here. Used in other files of this folder and through // the whole project. const path = require('path'); const fs = require('fs'); // Lodash as base. const utils = require('lodash'); const validator = require('validator'); const debug = require('debug'); const promisify = require('es6-promisify'); const svn = require('node-svn-ultimate'); const download = require('download'); const requireDir = require('require-directory'); const pMap = require('p-map'); const pkgName = require('../package.json').name; const errMsgs = require('./errMsgs'); utils.pathToTag = (fullPath) => { const res = path.basename(fullPath, '.js'); if (!res || res === fullPath) { throw new Error(errMsgs.badPath); } else { return res; } }; utils.dbg = fullPath => debug(`${pkgName}:${utils.pathToTag(fullPath)}`); utils.validator = validator; utils.promisify = promisify; utils.pMap = pMap; utils.downBase = (url, dst) => new Promise((resolve, reject) => // "force" needed to allow overwrite the old file (if present). svn.commands.export(url, dst, { force: true }, (err) => { if (err) { reject(err); return; } resolve(); }) ); utils.downFile = download; utils.readFile = promisify(fs.readFile); utils.writeFile = promisify(fs.writeFile); // TODO: Change to async, not a big deal, only once at the start. utils.requireDir = requireDir; module.exports = utils;