Skip to content

Commit

Permalink
Merge branch 'master' into ft_custom_format
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	lib/args.js
	lib/index.js
  • Loading branch information
Philipp Tusch committed Sep 1, 2015
2 parents ea4d629 + 8d6a176 commit 6fa44ef
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 35 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Options
* `--csv` output in csv format.
* `--out [filepath]` write the data to a specific file.
* `--customPath` to add a custom Format file in JSON
* `--exclude [list]` exclude modules which licenses are in the comma-separated list from the output

Examples
--------
Expand All @@ -69,7 +70,8 @@ Examples
license-checker --json > /path/to/licenses.json
license-checker --csv --out /path/to/licenses.csv
license-checker --unknown
license-checker --customPath customFormatExample.js
license-checker --customPath customFormatExample.js
license-checker --exclude 'MIT, MIT/X11, BSD, ISC'
```

Requiring
Expand Down
37 changes: 19 additions & 18 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ http://yuilibrary.com/license/
*/

var nopt = require('nopt'),
chalk = require('chalk'),
known = {
json: Boolean,
csv: Boolean,
markdown: Boolean,
out: require('path'),
unknown: Boolean,
version: Boolean,
color: Boolean,
start: String,
help: Boolean,
customPath: require('path'),
customFormat: { }
},
shorts = {
"v" : ["--version"],
"h" : ["--help"]
};
chalk = require('chalk'),
known = {
json: Boolean,
csv: Boolean,
markdown: Boolean,
out: require('path'),
unknown: Boolean,
version: Boolean,
color: Boolean,
start: String,
help: Boolean,
exclude: String,
customPath: require('path'),
customFormat: { }
},
shorts = {
"v" : ["--version"],
"h" : ["--help"]
};

var raw = function (args) {
return nopt(known, shorts, (args || process.argv));
Expand Down
49 changes: 33 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ var license = require('./license');

var flatten = function(options) {
var moduleInfo = { licenses: UNKNOWN },
json = options.deps,
data = options.data,
key = json.name + '@' + json.version,
colorize = options.color,
licenseData, files = [], licenseFile;
json = options.deps,
data = options.data,
key = json.name + '@' + json.version,
colorize = options.color,
unknown = options.unknown,
licenseData, files = [], licenseFile;

if (colorize) {
moduleInfo = { licenses: chalk.bold.red(UNKNOWN) };
Expand Down Expand Up @@ -48,6 +49,10 @@ var flatten = function(options) {
}
}

if (unknown) {
moduleInfo.dependencyPath = json.path;
}

//Build custom format output
if (options.customFormat !== undefined) {
Object.keys(options.customFormat).forEach(function forEachCallback(item) {
Expand Down Expand Up @@ -120,8 +125,8 @@ var flatten = function(options) {
deps: childDependency,
data: data,
color: colorize,
filter: options.filter,
customFormat: options.customFormat
unknown: unknown,
customFormat: options.customFormat
});
});
}
Expand All @@ -133,14 +138,17 @@ exports.init = function(options, callback) {

read(options.start, { dev: true }, function(err, json) {
var data = flatten({
deps: json,
data: {},
color: options.color,
filter: options.filter,
customFormat: options.customFormat
}),
colorize = options.color,
sorted = {};
deps: json,
data: {},
color: options.color,
unknown: options.unknown,
customFormat: options.customFormat
filter: options.filter
}),
colorize = options.color,
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 @@ -157,7 +165,16 @@ exports.init = function(options, callback) {
sorted[item] = data[item];
}
});
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
Original file line number Diff line number Diff line change
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 6fa44ef

Please sign in to comment.