Skip to content

Instantly share code, notes, and snippets.

@gs-akhan
Created April 22, 2014 18:40
Show Gist options
  • Save gs-akhan/11189902 to your computer and use it in GitHub Desktop.
Save gs-akhan/11189902 to your computer and use it in GitHub Desktop.
Grunt task to count the number of lines given from bunch of files
var fs = require('fs');
var path = require('path');
module.exports = function(grunt) {
grunt.registerMultiTask('linecounter', 'counts the number of lines in files', function( ) {
var count = 0;
var done = this.async();
this.files[0].src.forEach(function(a) {
console.log(a);
fs.createReadStream(a).on('data', function(chunk) {
for (i=0; i < chunk.length; ++i)
if (chunk[i] === 10) count++;
}).on('end', function() {
console.log(count);
//How do i know when the last file is read and then only display the count value
});
});
});
grunt.initConfig({
linecounter : {
t1 : {
src : ['UI/**/*.js']
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment