add hintStagedFiles, use in pre-commit hook

This commit is contained in:
Joe Fleming 2014-12-12 14:28:29 -07:00
parent c281af4568
commit 1b8a0dd3d6
2 changed files with 29 additions and 1 deletions

View file

@ -49,7 +49,7 @@
"scripts": {
"test": "grunt test --use-jruby",
"server": "grunt server",
"precommit": "grunt jshint",
"precommit": "grunt hintStagedFiles",
"prepush": "echo"
},
"repository": {

28
tasks/jshint.js Normal file
View file

@ -0,0 +1,28 @@
var path = require('path');
var workingPath = path.resolve(__dirname, '..');
var simplegit = require('simple-git')(workingPath);
module.exports = function (grunt) {
grunt.registerTask('hintStagedFiles', 'JSHint staged filed', function () {
grunt.log.debug('git working path', workingPath);
var done = this.async();
var files = simplegit.diff('--name-only --cached', function (err, files) {
// match these patterns
var patterns = grunt.config.get('jshint.source.files.src');
files = files.split('\n').filter(Boolean).map(function (file) {
if (file.length) {
return path.join(workingPath, file);
}
});
files = grunt.file.match(patterns, files);
grunt.log.debug(files);
grunt.config.set('jshint.staged.files.src', files);
grunt.task.run(['jshint:staged']);
done();
});
});
};