Skip to content

Commit

Permalink
added options.filter to checker.init
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Nov 21, 2014
1 parent 8e5f5f0 commit 63e5f9c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ var chalk = require('chalk');
var treeify = require('treeify');
var license = require('./license');

var flatten = function(json, data, colorize) {
var flatten = function(options) {
var moduleInfo = {licenses: UNKNOWN},
json = options.deps,
data = options.data,
colorize = options.color,
licenseData, files, licenseFile, key;

if (colorize) {
Expand Down Expand Up @@ -81,10 +84,18 @@ var flatten = function(json, data, colorize) {
Object.keys(json.dependencies).forEach(function(name) {
var childDependency = json.dependencies[name],
dependencyId = childDependency.name + '@' + childDependency.version;
if (options.filter && options.filter(name, childDependency)) {
return;
}
if (data[dependencyId]) { // already exists
return;
}
data = flatten(childDependency, data, colorize);
data = flatten({
deps: childDependency,
data: data,
color: colorize,
filter: options.filter
});
});
}
return data;
Expand All @@ -94,7 +105,12 @@ exports.init = function(options, callback) {

console.log('scanning' , options.start);
read(options.start, { dev: true }, function(err, json) {
var data = flatten(json, {}, options.color),
var data = flatten({
deps: json,
data: {},
color: options.color,
filter: options.filter
}),
sorted = {};
Object.keys(data).sort().forEach(function(item) {
if (options.unknown) {
Expand Down

0 comments on commit 63e5f9c

Please sign in to comment.