Created
August 22, 2014 21:30
-
-
Save santthosh/d86e9f1e547c201b319d to your computer and use it in GitHub Desktop.
Get details on nodejs project dependencies from package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* | |
* Generates a report of npm components the project uses for compliance | |
* Author: @santthosh | |
*/ | |
var npm = require('npm'); | |
var viewPackageInfo = function(err, data) { | |
for(var version in data) { | |
if(data.hasOwnProperty(version)) { | |
var info = data[version]; | |
var repositoryUrl; | |
if(typeof info.repository.url !== 'undefined') { | |
repositoryUrl = info.repository.url; | |
} else { | |
repositoryUrl = 'undefined'; | |
} | |
var author; | |
if(typeof info.author !== 'undefined') { | |
author = info.author.name; | |
} else { | |
author = 'undefined'; | |
} | |
var licenseType, licenseUrl; | |
if(typeof info.licenses !== 'undefined') { | |
licenseType = info.licenses.type; | |
licenseUrl = info.licenses.url; | |
} else { | |
licenseType = 'undefined'; | |
licenseUrl = 'undefined'; | |
} | |
console.log(info.name + | |
',' + repositoryUrl + | |
',' + author + | |
',' + licenseType + | |
',' + licenseUrl); | |
} | |
} | |
}; | |
npm.load(function (er, npm) { | |
npm.config.set('json',true); | |
npm.config.set('depth',0); | |
npm.commands.list([],true,function(err, data) { | |
var dependencies = []; | |
for(var key in data.dependencies) { | |
if(data.dependencies.hasOwnProperty(key)) { | |
npm.commands.view([key],true,viewPackageInfo); | |
} | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment