Permalink
Browse files

take multiple files or directories as input

  • Loading branch information...
1 parent 1a6340d commit f7293ed11f9af60e6fee4d856aa89f5f5469a606 @substack committed Aug 13, 2012
Showing with 37 additions and 12 deletions.
  1. +10 −4 bin/cmd.js
  2. +21 −6 index.js
  3. +2 −1 package.json
  4. +4 −1 readme.markdown
View
@@ -1,17 +1,23 @@
#!/usr/bin/env node
var codebux = require('../');
-var dir = process.argv[2];
var path = require('path');
var Stream = require('stream');
-if (process.argv.length === 2) {
- return console.error('usage: codebux [file or directory]');
+var dirs = process.argv.slice(2);
+if (dirs.length === 0) {
+ return console.error([
+ 'usage: codebux [files or directories...]',
+ '',
+ 'Recursively trace the static require() dependency graph for every file'
+ + 'or directory provided.',
+ ''
+ ].join('\n'));
}
console.log(formatPrice(100) + ' # initial stipend');
-var s = codebux(dir);
+var s = codebux(dirs);
var errors = [];
View
@@ -5,9 +5,16 @@ var path = require('path');
var EventEmitter = require('events').EventEmitter;
var complexityCost = require('./lib/complexity');
var syntaxError = require('syntax-error');
+var commondir = require('commondir');
-module.exports = function (dir, cb) {
- dir = path.resolve(dir);
+module.exports = function (dirs, cb) {
+ if (!Array.isArray(dirs)) dirs = [ dirs ];
+
+ dirs = dirs.map(function (d) {
+ return path.resolve(d);
+ });
+ var dir = commondir(dirs);
+
var emitter = new EventEmitter;
emitter.total = 0;
@@ -30,12 +37,20 @@ module.exports = function (dir, cb) {
emitter.emit('total', emitter.total);
}
+ var files = dirs.map(function (d) {
+ return require.resolve(/\.js$/.test(d) ? d : d + '/')
+ });
+
process.nextTick(function (file) {
record(100, 'initial stipend');
- walk(file, function () {
- emitter.emit('end', emitter.total);
- });
- }.bind(null, require.resolve(/\.js$/.test(dir) ? dir : dir + '/')));
+
+ (function next () {
+ if (files.length === 0) {
+ emitter.emit('end', emitter.total);
+ }
+ else walk(files.shift(), next)
+ })();
+ });
var walked = {};
View
@@ -10,7 +10,8 @@
"falafel" : "~0.1.1",
"detective" : "~0.2.0",
"resolve" : "~0.2.2",
- "syntax-error" : "~0.0.0"
+ "syntax-error" : "~0.0.0",
+ "commondir" : "~0.0.1"
},
"repository" : {
"type" : "git",
View
@@ -41,7 +41,10 @@ $ codebux ~/projects/node-browserify
# usage
```
-usage: codebux [file or directory]
+usage: codebux [files or directories...]
+
+Recursively trace the static require() dependency graph for every file or
+directory provided.
```
# methods

0 comments on commit f7293ed

Please sign in to comment.