-
-
Save paulking00/28f38ed875589c94f2f1 to your computer and use it in GitHub Desktop.
With 1 level of folder recursion
This file contains 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var path = require('path'); | |
var jshint = require('jshint').JSHINT; | |
var async = require('async'); | |
var foldersToProcess = [ | |
'app' | |
]; | |
foldersToProcess.forEach(function(folder) { | |
processDirs("www/" + folder); | |
}); | |
function processDirs(dir, callback) { | |
fs.readdir(dir, function(err, list) { | |
if (err) { | |
console.log('processFiles err: ' + err); | |
return; | |
} | |
list.forEach(function(subdir) { | |
subdir = dir + '/' + subdir; | |
fs.stat(subdir, function(err, stat) { | |
if(stat.isDirectory()) { | |
processFiles(subdir); | |
} else { | |
var file = subdir; | |
if(path.extname(file) === ".js") { | |
lintFile(file, function(hasError) { | |
}); | |
} | |
} | |
}); | |
}); | |
}); | |
} | |
function processFiles(dir, callback) { | |
var errorCount = 0; | |
fs.readdir(dir, function(err, list) { | |
if (err) { | |
console.log('processFiles err: ' + err); | |
return; | |
} | |
async.eachSeries(list, function(file, innercallback) { | |
file = dir + '/' + file; | |
fs.stat(file, function(err, stat) { | |
if(!stat.isDirectory()) { | |
if(path.extname(file) === ".js") { | |
lintFile(file, function(hasError) { | |
if(hasError) { | |
errorCount++; | |
} | |
innercallback(); | |
}); | |
} else { | |
innercallback(); | |
} | |
} else { | |
innercallback(); | |
} | |
}); | |
}, function(error) { | |
if(errorCount > 0) { | |
process.exit(1); | |
} | |
}); | |
}); | |
} | |
function lintFile(file, callback) { | |
//console.log("Linting " + file); | |
fs.readFile(file, function(err, data) { | |
if(err) { | |
console.log('Error: ' + err); | |
return; | |
} | |
if(jshint(data.toString())) { | |
console.log('File ' + file + ' has no errors.'); | |
console.log('-----------------------------------------'); | |
callback(false); | |
} else { | |
console.log('Errors in file ' + file); | |
var out = jshint.data(), | |
errors = out.errors; | |
for(var j = 0; j < errors.length; j++) { | |
if (errors[j] != null) console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' + errors[j].evidence); | |
} | |
console.log('-----------------------------------------'); | |
callback(true); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment