Skip to content

Commit

Permalink
Merge branch 'master' into ft_onlyunknown
Browse files Browse the repository at this point in the history
Conflicts:
	lib/index.js
  • Loading branch information
Philipp Tusch committed Sep 1, 2015
2 parents c287959 + 8d6a176 commit efe23d9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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
--------
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/args.js
Expand Up @@ -16,6 +16,7 @@ var nopt = require('nopt'),
version: Boolean,
color: Boolean,
start: String,
exclude: String,
help: Boolean
},
shorts = {
Expand Down
15 changes: 13 additions & 2 deletions lib/index.js
Expand Up @@ -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) {
Expand All @@ -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);
});
};

Expand Down
20 changes: 20 additions & 0 deletions tests/test.js
Expand Up @@ -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');
Expand Down

0 comments on commit efe23d9

Please sign in to comment.