From 99a6b2179f01309e2fc05e35a8284c13a97e7e99 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 14 Apr 2015 15:21:09 +0200 Subject: [PATCH] * Changed API of dumpLicenses() callback to improve programmatic use * Sorting and file output are nuw done as part of dumpLicenses() --- README.md | 4 ++++ bin/npm-license-crawler | 40 ++-------------------------------------- lib/directoryreader.js | 1 - lib/index.js | 35 +++++++++++++++++++++++++++++++++-- package.json | 2 +- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index af22bbc..065691e 100644 --- a/README.md +++ b/README.md @@ -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 ---- diff --git a/bin/npm-license-crawler b/bin/npm-license-crawler index 1f66a44..350de42 100644 --- a/bin/npm-license-crawler +++ b/bin/npm-license-crawler @@ -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'), @@ -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 }) } \ No newline at end of file diff --git a/lib/directoryreader.js b/lib/directoryreader.js index b2f8093..1cc1c87 100644 --- a/lib/directoryreader.js +++ b/lib/directoryreader.js @@ -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; diff --git a/lib/index.js b/lib/index.js index 713debe..80460c9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 = []; @@ -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); } }); }; diff --git a/package.json b/package.json index 023f4e3..1c7be23 100644 --- a/package.json +++ b/package.json @@ -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": {