Last active
October 1, 2015 15:29
-
-
Save aharris/ae4f55355b5105559fa3 to your computer and use it in GitHub Desktop.
Pre commit hooks with gulp and grunt
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
// npm install | |
// Require dependencies | |
// set up git hooks | |
// set up jshint | |
// register Task | |
// NOTES: requires each user to run a grunt task to create the pre-commit hook | |
module.exports = function(grunt) { | |
grunt.loadNpmTasks('grunt-githooks'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.initConfig({ | |
githooks: { | |
all: { | |
'pre-commit': 'jshint' | |
} | |
}, | |
jshint: { | |
options: { | |
reporter: require('jshint-stylish') | |
}, | |
all: ['*.js'] | |
} | |
}); | |
grunt.registerTask('default', [ 'githooks' ]); | |
}; |
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
// npm install | |
// show the hook already exists now | |
// create task | |
// NOTES: pre commit hook is created by running nom install | |
var gulp = require('gulp'); | |
var guppy = require('git-guppy')(gulp); | |
gulp.task('pre-commit', guppy.src('pre-commit', function (files) { | |
var gulpFilter = require('gulp-filter'); | |
var jshint = require('gulp-jshint'); | |
var stylish = require('jshint-stylish'); | |
var filter = gulpFilter(['*.js']); | |
return gulp.src(files) | |
.pipe(filter) | |
.pipe(jshint()) | |
.pipe(jshint.reporter(stylish)) | |
.pipe(jshint.reporter('fail')); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment