npm-link-up
Version:
Use this package to link your projects together for local development.
50 lines (49 loc) • 1.76 kB
JavaScript
;
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");
const nluUtils = require("./utils");
exports.getIgnore = (conf, opts) => {
const ignore = nluUtils.getUniqueList(nluUtils.flattenDeep([conf.ignore, always_ignore_1.default]))
.map(d => String(d || '').trim())
.filter(Boolean)
.map((item) => 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((item) => {
opts.verbosity > 1 && logging_1.default.warning(`ignored => ${item}`);
});
}
return ignore;
};
exports.getSearchRoots = (opts, conf) => {
let searchRoots = [];
if (opts.search_from_home) {
searchRoots.push(path.resolve(process.env.HOME));
}
else if (opts.search_root && opts.search_root.length > 0) {
searchRoots.push(opts.search_root);
}
else {
searchRoots.push(conf.searchRoots);
searchRoots.push(opts.search_root_append);
searchRoots.push(conf.searchRoot);
}
const searchRootsReduced = [];
nluUtils.getUniqueList(nluUtils.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;
};