UNPKG

nlu

Version:

Use this package to link your projects together for local development.

48 lines (47 loc) 1.79 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const chalk_1 = require("chalk"); const logging_1 = require("./logging"); const always_ignore_1 = require("./always-ignore"); exports.getIgnore = function (conf, opts) { const ignore = (conf.ignore || []).concat(always_ignore_1.default) .filter(function (item, index, arr) { return arr.indexOf(item) === index; }) .map(function (item) { return new RegExp(item); }); if (ignore.length > 0) { opts.verbosity > 1 && logging_1.default.info(chalk_1.default.underline('NPM-Link-Up will ignore paths that match any of the following regular expressions => ')); ignore.forEach(function (item) { opts.verbosity > 1 && logging_1.default.warning(`ignored => ${item}`); }); } return ignore; }; const flattenDeep = function (arr1) { return arr1.reduce((acc, val) => Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val), []); }; exports.getSearchRoots = function (opts, conf) { let searchRoots = []; if (opts.search_from_home) { searchRoots.push(path.resolve(process.env.HOME)); } if (opts.search_root && opts.search_root.length > 0) { searchRoots.push(opts.search_root); } searchRoots.push([].concat(conf.searchRoots || []).concat(opts.search_root_append || [])); const searchRootsReduced = []; flattenDeep(searchRoots).map(d => String(d || '').trim()).filter(Boolean) .sort((a, b) => (a.length - b.length)) .filter((v, i, a) => { const s = !a.some(p => { return p.startsWith(v + '/'); }); if (s) { searchRootsReduced.push(v); } }); return searchRootsReduced; };