From b28028ac4082842143b0f528d6bc539da6ccb419 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Thu, 21 Sep 2017 12:49:18 -0400 Subject: mega changes, including updates and X --- hooks/before_prepare/02_jshint.js | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 hooks/before_prepare/02_jshint.js (limited to 'hooks/before_prepare/02_jshint.js') diff --git a/hooks/before_prepare/02_jshint.js b/hooks/before_prepare/02_jshint.js new file mode 100755 index 00000000..fff7775d --- /dev/null +++ b/hooks/before_prepare/02_jshint.js @@ -0,0 +1,73 @@ +#!/usr/bin/env node + +var fs = require('fs'); +var path = require('path'); +var jshint = require('jshint').JSHINT; +var async = require('async'); + +var foldersToProcess = [ + 'js' +]; + +foldersToProcess.forEach(function(folder) { + processFiles("www/" + folder); +}); + +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++) { + console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' + +errors[j].evidence); + } + console.log('-----------------------------------------'); + callback(true); + } + }); +} + -- cgit v1.2.3