Comparing version 0.0.6 to 0.1.0
@@ -18,11 +18,16 @@ #!/usr/bin/env node | ||
pjson = require('../package.json'), | ||
nlf = require('../lib/nlf'); | ||
nlf = require('../lib/nlf'), | ||
options = { | ||
directory: process.cwd() | ||
}; | ||
program | ||
.command('nlf') | ||
.version(pjson.version) | ||
.option('-d, --no-dev', 'exclude development dependencies') | ||
.parse(process.argv); | ||
nlf.find(process.cwd(), function (err, data) { | ||
options.production = !program.dev; | ||
nlf.find(options, function (err, data) { | ||
if (err) { | ||
@@ -29,0 +34,0 @@ console.error(err); |
@@ -21,10 +21,41 @@ /** | ||
var stringify = require('json-stringify-safe'); | ||
/** | ||
* Is this module a development dependency of its parent? | ||
* | ||
* @param {Object} moduleData The module's data | ||
* @return {Boolean} True if the module is a production dependency | ||
*/ | ||
function isDevDependency(moduleData) { | ||
// this might be the root object - which by definition is production | ||
if (moduleData.parent === undefined) { | ||
return false; | ||
} | ||
var dependencies = moduleData.parent.devDependencies || {}, | ||
dependencyName; | ||
// look for this module in the production dependencies of the parent | ||
// and return true if it is found | ||
for (dependencyName in dependencies) { | ||
if (dependencies.hasOwnProperty(dependencyName)) { | ||
if (dependencyName === moduleData.name) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Parse the data returned by readInstalled | ||
* | ||
* @param {Object} data readInstalled data | ||
* @param {Array} output The output array | ||
* @param {Function} callback Callback function | ||
* @param {Object} data readInstalled data | ||
* @param {Object} options the options object | ||
* @param {Array} output The output array | ||
* @param {Function} callback Callback function | ||
*/ | ||
function parseInstalled(data, callback) { | ||
function parseInstalled(data, options, callback) { | ||
@@ -43,2 +74,8 @@ // count of outstanding unfinished parse functions | ||
// don't parse this module if it is a development dependency | ||
// and we are only looking for production dependencies | ||
if (options.production && isDevDependency(moduleData)) { | ||
return; | ||
} | ||
// a module with this ID (name@version) is already in the output | ||
@@ -230,2 +267,8 @@ // collection, we don't need to process it again | ||
/** | ||
* Convert an object to an array | ||
* | ||
* @param {Object} object The object | ||
* @return {Array} An array made from each property of the object | ||
*/ | ||
function convertToArray(object) { | ||
@@ -236,3 +279,2 @@ | ||
for (propertyName in object) { | ||
@@ -245,3 +287,30 @@ if (object.hasOwnProperty(propertyName)) { | ||
return output; | ||
} | ||
/** | ||
* Process the options | ||
* | ||
* @param {Object} options The options object passed into find() | ||
* @return {Object} Options that have been massaged | ||
*/ | ||
function processOptions(options) { | ||
options = options || {}; | ||
if (typeof options !== 'object') { | ||
throw new Error('options must be an object'); | ||
} | ||
options.directory = options.directory || process.cwd(); | ||
options.production = options.production || false; | ||
if (typeof options.directory !== 'string') { | ||
throw new Error('options.directory must be a string'); | ||
} | ||
if (typeof options.production !== 'boolean') { | ||
throw new Error('options.production must be a boolean'); | ||
} | ||
return options; | ||
} | ||
@@ -252,10 +321,12 @@ | ||
* | ||
* @param {String} directory Relative or absolute path of | ||
* project folder containing package.json | ||
* @param {Object} options Options object | ||
* @param {Function} callback Callback function | ||
*/ | ||
function find(directory, callback) { | ||
function find(options, callback) { | ||
// default to cwd | ||
directory = directory || process.cwd(); | ||
// process arguments | ||
if (typeof options === 'function' && typeof callback === undefined) { | ||
callback = options; | ||
} | ||
options = processOptions(options); | ||
@@ -273,3 +344,3 @@ /** | ||
// use npm read-installed module to search out all the node modules | ||
readInstalled(directory, null, log, function (err, data) { | ||
readInstalled(options.directory, null, log, function (err, data) { | ||
@@ -282,3 +353,3 @@ if (err) { | ||
// parse the read-installed data | ||
parseInstalled(data, function (err, output) { | ||
parseInstalled(data, options, function (err, output) { | ||
@@ -285,0 +356,0 @@ if (err) { |
@@ -6,3 +6,3 @@ { | ||
"author": "Ian Kelly <iandotkelly@gmail.com>", | ||
"version": "0.0.6", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -35,3 +35,3 @@ "bin" : { | ||
"checker", | ||
"finer", | ||
"finder", | ||
"audit", | ||
@@ -38,0 +38,0 @@ "legal", |
@@ -46,2 +46,9 @@ # Node License Finder (nlf) | ||
To exclude development dependences and only analyze dependencies for production: | ||
```sh | ||
$ cd my-module | ||
$ nlf -d | ||
``` | ||
### Tests | ||
@@ -51,5 +58,2 @@ | ||
If you contribute to the project, tests are written in [mocha](http://visionmedia.github.com/mocha/), using [should.js](https://github.com/visionmedia/should.js/) or the node.js assert module. | ||
```sh | ||
@@ -60,2 +64,3 @@ $ cd nlf | ||
``` | ||
If you contribute to the project, tests are written in [mocha](http://visionmedia.github.com/mocha/), using [should.js](https://github.com/visionmedia/should.js/) or the node.js assert module. | ||
@@ -62,0 +67,0 @@ ## License |
@@ -19,3 +19,3 @@ /** | ||
nlf.find(path.join(__dirname, '../..'), function (err, data) { | ||
nlf.find({ directory: path.join(__dirname, '../..') }, function (err, data) { | ||
if (err) { | ||
@@ -22,0 +22,0 @@ return done(err); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
303550
24
1065
88