From d87484a69ace6191a140dbd2bc6ac829312b2c98 Mon Sep 17 00:00:00 2001 From: Vildan Softic Date: Fri, 27 Mar 2020 11:36:41 +0100 Subject: [PATCH] feat(deps): skipping dependencies via CLI this allows to skip inidividual dependencies by name by providing -s with a list of comma separated dependency names --- index.js | 54 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) mode change 100644 => 100755 index.js diff --git a/index.js b/index.js old mode 100644 new mode 100755 index 447825f..00500a0 --- a/index.js +++ b/index.js @@ -11,10 +11,15 @@ var yargs = require('yargs') baseDir: { alias: 'b', default: process.cwd(), + }, + skippedDependencies: { + alias: 's', + default: '', } }) .array('baseDir') .example('$0 -o ./tpn', 'run the tool and output text and backing json to ${projectRoot}/tpn directory.') + .example('$0 -s fsevents,angular,everything', 'skip the given dependencies (comma-seprated) for checking') .example('$0 -b ./some/path/to/projectDir', 'run the tool for Bower/NPM projects in another directory.') .example('$0 -o tpn -b ./some/path/to/projectDir', 'run the tool in some other directory and dump the output in a directory called "tpn" there.'); @@ -109,42 +114,51 @@ function getNpmLicenses() { } return merged; }).then((result) => { - + // we want to exclude the top-level project from being included var dir = result[Object.keys(result)[0]]['dir']; var topLevelProjectInfo = jetpack.read(path.join(dir, 'package.json'), 'json'); + var keys = Object.getOwnPropertyNames(result).filter((k) => { return k !== `${topLevelProjectInfo.name}@${topLevelProjectInfo.version}`; }); + var skippedDeps = !yargs.argv.skippedDependencies.trim() + ? [] + : yargs.argv.skippedDependencies.split(','); + if (skippedDeps.length > 0) { + console.log("Skipping dependencies", yargs.argv.skippedDependencies); + keys = keys.filter((k) => skippedDeps.map((s) => k.startsWith(s)).filter(s => s).length < 1); + } + return bluebird.map(keys, (key) => { console.log('processing', key); var package = result[key]; var defaultPackagePath = `${package['dir']}/node_modules/${package.name}/package.json`; - + var itemAtPath = jetpack.exists(defaultPackagePath); var packagePath = [defaultPackagePath]; - + if (itemAtPath !== 'file') { packagePath = jetpack.find(package['dir'], { matching: `**/node_modules/${package.name}/package.json` }); } - + var packageJson = ""; - + if (packagePath && packagePath[0]) { packageJson = jetpack.read(packagePath[0], 'json'); } else { return Promise.reject(`${package.name}: unable to locate package.json`); } - + console.log('processing', packageJson.name, 'for authors and licenseText'); - + var props = {}; - + props.authors = (packageJson.author && getAttributionForAuthor(packageJson.author)) || (packageJson.contributors && packageJson.contributors @@ -157,9 +171,9 @@ function getNpmLicenses() { return getAttributionForAuthor(m); }).join(', ')); - + var licenseFile = package.licenseFile; - + try { if (licenseFile && jetpack.exists(licenseFile) && path.basename(licenseFile).match(/license/i)) { props.licenseText = jetpack.read(licenseFile); @@ -169,12 +183,12 @@ function getNpmLicenses() { } catch (e) { console.warn(e); - return { + return { authors: '', licenseText: '' }; } - + return { ignore: false, name: package.name, @@ -233,21 +247,21 @@ function getBowerLicenses() { // npm license check didn't work // try to get the license and package info from .bower.json first // because it has more metadata than the plain bower.json - + var package = ''; - + try { package = jetpack.read(path.join(absPath, '.bower.json'), 'json'); } catch (e) { package = jetpack.read(path.join(absPath, 'bower.json'), 'json'); } - + console.log('processing', package.name); // assumptions here based on https://github.com/bower/spec/blob/master/json.md // extract necessary properties as described in TL;DR above var url = package["_source"] || (package.repository && package.repository.url) || package.url || package.homepage; - + var authors = ''; if (package.authors) { @@ -264,7 +278,7 @@ function getBowerLicenses() { .replace(/\//g, ''); } } - + // normalize the license object package.license = package.license || package.licenses; @@ -273,7 +287,7 @@ function getBowerLicenses() { : _.isArray(package.license) ? package.license.join(',') : package.licenses; - + // find the license file if it exists var licensePath = _.find(component.children, c => { return /licen[cs]e/i.test(c.name); @@ -284,7 +298,7 @@ function getBowerLicenses() { if (licensePath) { licenseText = jetpack.read(path.join(bowerComponentsDir, licensePath.relativePath)); } - + return { ignore: false, name: package.name, @@ -360,7 +374,7 @@ taim('Total Processing', bluebird.all([ var attribution = attributionSequence.join(`${os.EOL}${os.EOL}******************************${os.EOL}${os.EOL}`); var headerPath = path.join(options.outputDir, 'header.txt'); - + if (jetpack.exists(headerPath)) { var template = jetpack.read(headerPath); console.log('using template', template);