Skip to content

Commit

Permalink
Checking for valid path first
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
davglass committed May 4, 2015
1 parent e22b61d commit d85e355
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var flatten = function(options) {
data = options.data,
key = json.name + '@' + json.version,
colorize = options.color,
licenseData, files, licenseFile;
licenseData, files = [], licenseFile;

if (colorize) {
moduleInfo = { licenses: chalk.bold.red(UNKNOWN) };
Expand Down Expand Up @@ -66,10 +66,12 @@ var flatten = function(options) {
moduleInfo.licenses = license(json.readme);
}

files = fs.readdirSync(json.path).filter(function(filename) {
filename = filename.toUpperCase();
return filename.indexOf('LICENSE') > -1 || filename.indexOf('LICENCE') > -1 ;
});
if (json.path && fs.existsSync(json.path)) {
files = fs.readdirSync(json.path).filter(function(filename) {
filename = filename.toUpperCase();
return filename.indexOf('LICENSE') > -1 || filename.indexOf('LICENCE') > -1 ;
});
}

files.forEach(function(filename) {
licenseFile = path.join(json.path, filename);
Expand Down

0 comments on commit d85e355

Please sign in to comment.