Permalink
Browse files

Merge pull request #11 from dijs/rewrite

Rewrite
  • Loading branch information...
2 parents 5a58a47 + 918e19e commit 661011355e2ed3496beac2165d27a64ec4a64167 @dijs dijs committed Mar 24, 2015
Showing with 153 additions and 1,691 deletions.
  1. +6 −0 History.md
  2. +17 −18 bin/stats
  3. +20 −64 lib/find.js
  4. +79 −248 lib/parser.js
  5. +0 −1,341 lib/uglify/parser.js
  6. +24 −13 package.json
  7. +1 −1 test/test.functions.js
  8. +1 −1 test/test.http.js
  9. +1 −1 test/test.large.js
  10. +1 −1 test/test.simple.js
  11. +1 −1 test/test.trycatch.js
  12. +1 −1 test/test.while.js
  13. +1 −1 test/test.with.js
View
@@ -1,3 +1,9 @@
+1.1.0 / 2015-03-24
+=================
+
+ * Modern rewrite of parser and file finder
+ * Finder now excludes node_modules directory and minified javascript
+ * Updated tests to reflect new parser (Esprima)
1.0.0 / 2012-02-26
==================
View
@@ -4,9 +4,9 @@
* Module dependencies.
*/
-var stats = require('../')
- , program = require('commander')
- , fs = require('fs');
+var stats = require('../'),
+ program = require('commander'),
+ fs = require('fs');
/**
* Statistics.
@@ -38,31 +38,30 @@ var paths = program.args;
// process
var totals = {};
-stats.find(paths, function(err, files){
- if (err) throw err;
- var pending = files.length;
- files.forEach(function(file){
- fs.readFile(file, 'utf8', function(err, str){
- if (err) throw err;
- statistics[file] = stats.parse(str, program);
- Object.keys(statistics[file]).forEach(function(key){
- totals[key] = (totals[key] || 0) + statistics[file][key];
- });
- --pending || done();
- });
+
+stats.find(paths, {
+ match: /.\.js$/,
+ exclude: /.\.min\.js$/,
+ excludeDir: ['node_modules']
+}, function(content, file) {
+ statistics[file] = stats.parse(content);
+ Object.keys(statistics[file]).forEach(function(key) {
+ totals[key] = (totals[key] || 0) + statistics[file][key];
});
-});
+}, done);
// finished
function done() {
if (program.text) {}
var format = stats.formats[program.format];
if (!format) throw new Error('invalid format "' + program.format + '"');
- var obj = { totals: totals };
+ var obj = {
+ totals: totals
+ };
totals.files = Object.keys(statistics).length;
if (!program.totals) {
for (var file in statistics) obj[file] = statistics[file];
}
format(obj);
-}
+}
View
@@ -1,3 +1,6 @@
+'use strict';
+
+/* jshint node:true */
/*!
* stats - find
@@ -9,75 +12,28 @@
* Module dependencies.
*/
-var fs = require('fs')
- , path = require('path')
- , join = path.join
- , extname = path.extname
- , noop = function(){};
+var async = require('async');
+var dir = require('node-dir');
/**
- * Find JavaScript files by the given `paths`
- * and callback `fn(err, files)`.
+ * Fire fn for each file in `paths`
+ * and callback `fn(err)`.
*
* @param {Array} paths
+ * @param {Object} options
* @param {Function} fn
* @api public
*/
-module.exports = function(paths, fn){
- var pending = paths.length
- , ret = [];
-
- function find(path) {
- fs.stat(path, function(err, stat) {
- if (err) {
- fn(err);
- fn = noop;
- return
- }
-
- if (stat.isFile() && isJavaScript(path)) {
- ret.push(path);
- --pending || fn(null, ret);
- } else {
- fs.readdir(path, function(err, files){
- if (err) {
- fn(err);
- fn = noop;
- return
- }
-
- files.forEach(function(file){
- file = join(path, file);
- if (isJavaScript(file)) {
- ret.push(file);
- } else {
- ++pending;
- fs.stat(file, function(err, stat){
- if (err) return;
- if (!stat.isDirectory()) return --pending || fn(null, ret);
- find(file);
- });
- }
- });
-
- --pending || fn(null, ret);
- });
- }
- });
- }
-
- paths.forEach(find);
-};
-
-/**
- * Filter `file` by ".js" extension.
- *
- * @param {String} file
- * @return {Boolean}
- * @api private
- */
-
-function isJavaScript(file) {
- return '.js' == extname(file);
-}
+module.exports = function(paths, options, fn, callback) {
+ async.each(paths, function(path, done) {
+ dir.readFiles(path, options, function(err, content, filename, next) {
+ if (err) {
+ next(err);
+ } else {
+ fn(content, filename);
+ next();
+ }
+ }, done);
+ }, callback);
+};
Oops, something went wrong.

0 comments on commit 6610113

Please sign in to comment.