Created
December 10, 2013 06:18
-
-
Save vojtajina/7886470 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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