Skip to content

Commit

Permalink
Add --out flag for writing an output file.
Browse files Browse the repository at this point in the history
  • Loading branch information
timoxley committed Dec 4, 2014
1 parent 47bffc9 commit 7e80d50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions bin/license-checker
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ var path = require('path');
var fs = require('fs');

checker.init(args, function(json) {
if (args.json) return console.log(JSON.stringify(json, null, 2))
if (args.csv) return console.log(checker.asCSV(json))
var formattedOutput = '';
if (args.json) formattedOutput = JSON.stringify(json, null, 2);
else if (args.csv) formattedOutput = checker.asCSV(json);
else formattedOutput = checker.asTree(json);

checker.print(json);
if (args.out) {
var dir = path.dirname(args.out);
mkdirp.sync(dir);
fs.writeFileSync(args.out, formattedOutput, 'utf8');
} else {
console.log(formattedOutput);
}
});
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var nopt = require('nopt'),
known = {
json: Boolean,
csv: Boolean,
out: require('path'),
unknown: Boolean,
version: Boolean,
color: Boolean,
Expand Down
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ exports.init = function(options, callback) {
};

exports.print = function(sorted) {
console.log(treeify.asTree(sorted, true));
console.log(exports.asTree(sorted));
};

exports.asTree = function(sorted) {
return treeify.asTree(sorted, true);
};

exports.asCSV = function(sorted) {
Expand Down

0 comments on commit 7e80d50

Please sign in to comment.