Skip to content

Instantly share code, notes, and snippets.

@aharris
Last active October 1, 2015 15:29
Show Gist options
  • Save aharris/ae4f55355b5105559fa3 to your computer and use it in GitHub Desktop.
Save aharris/ae4f55355b5105559fa3 to your computer and use it in GitHub Desktop.
Pre commit hooks with gulp and grunt
// 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' ]);
};
// 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