Created
April 22, 2014 18:40
-
-
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
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('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