diff --git a/README.md b/README.md index 844e9d4..94b7c2e 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Options * `--json` output in json format. * `--csv` output in csv format. * `--out [filepath]` write the data to a specific file. +* `--exclude [list]` exclude modules which licenses are in the comma-separated list from the output Examples -------- @@ -69,6 +70,7 @@ Examples license-checker --json > /path/to/licenses.json license-checker --csv --out /path/to/licenses.csv license-checker --unknown +license-checker --exclude 'MIT, MIT/X11, BSD, ISC' ``` Requiring diff --git a/lib/args.js b/lib/args.js index cdb615b..854b150 100644 --- a/lib/args.js +++ b/lib/args.js @@ -16,6 +16,7 @@ var nopt = require('nopt'), version: Boolean, color: Boolean, start: String, + exclude: String, help: Boolean }, shorts = { diff --git a/lib/index.js b/lib/index.js index 971480d..b13d399 100644 --- a/lib/index.js +++ b/lib/index.js @@ -130,7 +130,9 @@ exports.init = function(options, callback) { filter: options.filter }), colorize = options.color, - sorted = {}; + sorted = {}, + filtered = {}, + exclude = options.exclude && options.exclude.replace(/^\s+|\s+$/g, '').split(/\s*,\s*/); Object.keys(data).sort().forEach(function(item) { if (options.unknown) { if (data[item].licenses && data[item].licenses !== UNKNOWN) { @@ -155,7 +157,16 @@ exports.init = function(options, callback) { } } }); - callback(sorted); + if (exclude) { + Object.keys(sorted).forEach(function(item) { + if (!(sorted[item].licenses && exclude.indexOf(sorted[item].licenses) !== -1)) { + filtered[item] = sorted[item]; + } + }); + } else { + filtered = sorted; + } + callback(filtered); }); }; diff --git a/tests/test.js b/tests/test.js index 98e078e..bb7cfce 100644 --- a/tests/test.js +++ b/tests/test.js @@ -57,6 +57,26 @@ var tests = { } } }, + 'should parse local with unknown': { + topic: function () { + var self = this; + + checker.init({ + start: path.join(__dirname, '../'), + exclude: "MIT, ISC" + }, function (filtered) { + self.callback(null, filtered); + }); + }, + 'and exclude MIT and ISC licensed modules from results': function (d) { + var excluded = true; + Object.keys(d).forEach(function(item) { + if (d[item].licenses && (d[item].licenses == "MIT" || d[item].licenses == "ISC")) + excluded = false; + }) + assert.ok(excluded); + } + }, 'should not error': { topic: function () { var lic = require('../lib/license.js');