Comparing version 0.1.0 to 0.2.0
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
var count = require('../src/count.js')(argv._); | ||
var count = require('../src/count.js')(argv); | ||
@@ -8,0 +8,0 @@ // provide clean output on exceptions rather than dumping a stack trace |
{ | ||
"name": "fcount", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Recursively count the number files in a directory given a pattern to match on.", | ||
@@ -34,4 +34,5 @@ "preferGlobal": "true", | ||
"devDependencies": { | ||
"mocha": "~1.20.1" | ||
"mocha": "~1.20.1", | ||
"chai": "~1.9.1" | ||
} | ||
} |
@@ -51,4 +51,3 @@ fcount | ||
- TESTS. It's 1.20am right now, need to come back and do later! | ||
@@ -10,13 +10,20 @@ var fs = require('fs'); | ||
// | ||
var file_counts = {}; | ||
var file_counts; | ||
var table = new Table({ | ||
head: ['File type', 'Count'], | ||
//colWidths: [100, 200] | ||
head: ['File type', 'Count'] | ||
}); | ||
function count(extensions) { | ||
copy_to_obj(extensions); | ||
function count(args, cb, dir) { | ||
dir = dir || null; | ||
file_counts = {}; | ||
walk(process.cwd(), function(err) { | ||
if (!(args._.length > 0)) { | ||
var message = chalk.red('Error: ') + chalk.yellow('fcount expects at least one extension to be passed in.'); | ||
return cb ? cb(message) : console.log(message); | ||
} | ||
copy_to_obj(args._); | ||
walk(dir, function(err) { | ||
if (err) return console.log(err); | ||
@@ -30,3 +37,7 @@ | ||
console.log(table.toString()); | ||
if (args.d) { | ||
return cb ? cb(file_counts) : file_counts; | ||
} else { | ||
return cb ? cb(table.toString()) : console.log(table.toString()); | ||
} | ||
}); | ||
@@ -94,3 +105,3 @@ } | ||
}); | ||
})(process.cwd()); | ||
})(process.cwd() + (dir || '')); | ||
} | ||
@@ -97,0 +108,0 @@ |
8710
18
226
2
53