module.exports = function(grunt) {
'use strict';
-
var build_output_dir = grunt.option('output-dir') || 'build',
- less_files = {};
+ less_files = {},
+ jshint_targets = grunt.option('jshint-targets');
less_files[build_output_dir + '/rng.css'] = 'src/editor/styles/main.less';
},
},
jshint: {
- all: ['Gruntfile.js', 'src/**/*.js'],
+ all: jshint_targets ? jshint_targets.split(',') : ['Gruntfile.js', 'src/**/*.js'],
options: {
jshintrc: '.jshintrc'
}
{src: ['libs/bootstrap/img/**'], dest: build_output_dir+'/'},
]
}
+ },
+ githooks: {
+ all: {
+ options: {
+ dest: grunt.option('git-hooks-dir') || '.git/hooks',
+ },
+ 'pre-commit': {
+ taskNames: ['lint'],
+ args: '--no-color',
+ template: 'pre-commit.template.js'
+ }
+ }
}
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');
+ grunt.loadNpmTasks('grunt-githooks');
grunt.registerTask('build', ['requirejs', 'less:production', 'copy:resources']);
grunt.registerTask('lint', ['jshint']);
"grunt-contrib-requirejs": "~0.4.1",
"grunt-contrib-less": "~0.8.3",
"grunt-contrib-jshint": "~0.7.2",
- "grunt-contrib-copy": "~0.4.1"
+ "grunt-contrib-copy": "~0.4.1",
+ "grunt-githooks": "~0.3.1"
}
}
--- /dev/null
+/* jshint node: true */
+'use strict';
+
+var exec = require('child_process').exec;
+var fs = require('fs');
+
+exec('git diff --cached --name-status', function (err, stdout) {
+ void(err);
+ var toLint = [];
+ stdout.split('\n').forEach(function(line) {
+ var filePath = line.split('\t')[1];
+ if(filePath && filePath.substr(-3) === '.js' && fs.existsSync(filePath)) {
+ toLint.push(filePath);
+ }
+ });
+ if(toLint.length) {
+ exec('grunt {{task}} {{args}} --jshint-targets=' + toLint.join(','), function (err, stdout) {
+ console.log(stdout);
+ process.exit(err ? -1 : 0);
+ });
+ }
+});