Skip to content

Commit

Permalink
* Changed API of dumpLicenses() callback to improve programmatic use
Browse files Browse the repository at this point in the history
* Sorting and file output are nuw done as part of dumpLicenses()
  • Loading branch information
mwittig committed Apr 14, 2015
1 parent 4f154bc commit 99a6b21
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 42 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ History
* Extended package description
* Corrected link syntax in README

* 20150414, V0.0.8
* Changed API of dumpLicenses() callback to improve programmatic use
* Sorting and file output are nuw done as part of dumpLicenses()

Todo
----

Expand Down
40 changes: 2 additions & 38 deletions bin/npm-license-crawler
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ var
dumpLicenses = require('../lib/index.js').dumpLicenses,
checker = require('license-checker'),
path = require('path'),
fs = require('fs'),
mkdirp = require('mkdirp'),
nopt = require('nopt'),
noptUsage = require('nopt-usage'),
noptDefaults = require('nopt-defaults'),
Expand Down Expand Up @@ -51,41 +49,7 @@ else if (parsedArgs.version) {
console.log(packageDescriptor.version);
}
else {
var fileOutput = parsedArgs.json || parsedArgs.csv;

dumpLicenses(parsedArgs, function(json) {
var result = {};
Object.keys(json).sort().forEach(function(item) {
if (json[item]) {
result[item] = json[item];
}
});

var dir;
if (fileOutput) {
// out put to file
if (parsedArgs.json) {
dir = path.dirname(parsedArgs.json);
mkdirp.sync(dir);
fs.writeFileSync(parsedArgs.json, JSON.stringify(result, null, 4) + '\n', 'utf8');
console.log('file written', parsedArgs.json);
}
if (parsedArgs.csv) {
dir = path.dirname(parsedArgs.csv);
mkdirp.sync(dir);
fs.writeFileSync(parsedArgs.csv, checker.asCSV(result), 'utf8');
console.log('file written', parsedArgs.csv);
}
}
else {
checker.print(result);
}
var nEntries = 0, key;
for (key in result) {
if (result.hasOwnProperty(key)) {
++nEntries;
}
}
console.log("Number of entries found:", nEntries);
dumpLicenses(parsedArgs, function(error, json) {
// intentionally left empty
})
}
1 change: 0 additions & 1 deletion lib/directoryreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var fs = require('fs'),
async = require('async'),
lstat = process.platform === 'win32' ? 'stat' : 'lstat',
lstatSync = process.platform === 'win32' ? 'statSync' : 'lstatSync';
;


module.exports = DirectoryReader;
Expand Down
35 changes: 33 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var path = require('path'),
checker = require('license-checker'),
extend = require('jquery-extend'),
async = require('async'),
fs = require('fs'),
mkdirp = require('mkdirp'),
licenses = {},
filePaths = [];

Expand Down Expand Up @@ -43,15 +45,44 @@ exports.dumpLicenses = function(args, callback) {

}, function (error) {
if (error) {
console.log(error)
console.log(error);
}
else {
callback(licenses);
var result = {};

Object.keys(licenses).sort().forEach(function(item) {
if (licenses[item]) {
result[item] = licenses[item];
}
});

var dir;
if (args.json || args.csv) {
// out put to file
if (args.json) {
dir = path.dirname(args.json);
mkdirp.sync(dir);
fs.writeFileSync(args.json, JSON.stringify(result, null, 4) + '\n', 'utf8');
console.log('file written', args.json);
}
if (args.csv) {
dir = path.dirname(args.csv);
mkdirp.sync(dir);
fs.writeFileSync(args.csv, checker.asCSV(result), 'utf8');
console.log('file written', args.csv);
}
}
else {
checker.print(result);
}
console.log("Number of entries found:", Object.keys(result).length);
}
callback(error, result);
});
}
else {
console.error(error);
callback(error, licenses);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-license-crawler",
"version": "0.0.7",
"version": "0.0.8",
"description": "Analyzes license information for multiple node.js modules (package.json files) as part of your software project.",
"main": "./lib/index.js",
"bin": {
Expand Down

0 comments on commit 99a6b21

Please sign in to comment.