Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created December 10, 2013 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtajina/7886470 to your computer and use it in GitHub Desktop.
Save vojtajina/7886470 to your computer and use it in GitHub Desktop.
var fs = require('q-io/fs');
var q = require('q');
var ignoreNodeDirectory = function(path) {
return path.indexOf('src/node/') === -1;
};
var EXPORT_REGEXP = /export/g;
fs.listTree('./src', ignoreNodeDirectory).then(function(files) {
var parsingAllFiles = [];
files.forEach(function(filepath) {
if (!/\.js$/.test(filepath)) {
return;
}
parsingAllFiles.push(fs.read(filepath).then(function(content) {
var match = content.toString().match(EXPORT_REGEXP);
return {file: filepath, count: match && match.length || 0};
}));
});
return q.all(parsingAllFiles);
}).then(function(stats) {
var normalized = stats.reduce(function(normalized, stat) {
normalized[stat.count] = normalized[stat.count] || 0;
normalized[stat.count]++;
return normalized;
}, {});
console.log(normalized);
}).done();
$ node count-exports.js
{ '0': 4,
'1': 84,
'2': 11,
'3': 5,
'4': 2,
'5': 3,
'7': 1,
'8': 2,
'9': 1,
'10': 2,
'14': 1,
'33': 1,
'67': 1,
'93': 1,
'94': 1,
'97': 1,
'108': 1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment