Skip to content

Instantly share code, notes, and snippets.

@kaanon
Created April 9, 2014 18:45
Show Gist options
  • Save kaanon/10301934 to your computer and use it in GitHub Desktop.
Save kaanon/10301934 to your computer and use it in GitHub Desktop.
/** Dependencies and Libraries */
var gulp = require('gulp'),
fs = require('fs'),
jshint = require('gulp-jshint'),
util = require('gulp-util'),
argv = require('yargs').argv,
args = argv['_'].slice(1);
/**
* Prebuild tasks
* - Make sure arguments, filename exist
* - JSHint on on js files
* @method
* @return {[type]}
*/
gulp.task('lint', function(){
var filename = argv.filename || false,
filepath = localPath + filename+'.html';
if(!filename){
util.log('Must pass in --filename');
return util.noop();
}
if(!fs.existsSync(filepath)){
util.log('Filename: '+ filepath + ' does not exist.');
return util.noop();
}
var content = require('fs').readFileSync(filepath, { encoding: 'utf8'});
var regex = /<\s*script\s+.*?src\s*=\s*"([^"]+?)".*?><\s*\/\s*script\s*>/gim;
var result, scripts = [];
while ( (result = regex.exec(content)) ) {
//Dont look at any lib files or min files, they are meant to be crazy
if(!result[1].match(/lib|min/)){
scripts.push(result[1].replace('..','.'));
}
}
return gulp.src(scripts)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment