Reputation: 705
I am starting with grunt, I have defined this task and work like a charm:
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
force: false,
options: {
evil: true,
regexdash: true,
browser: true,
wsh: true,
trailing: true,
multistr: true,
sub: true,
loopfunc: true,
expr: true,
jquery: true,
newcap: true,
plusplus: false,
curly: true,
eqeqeq: true,
globals: {
jQuery: true
}
},
src: ['workspace/**/*.js']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['jshint:src']);
};
Now, I would like to launch this task passing the src like a param (with git commited files).
I have tried this from a pre-commit script in my .git folder, but it does´t work:
var exec = require('child_process').exec;
exec('grunt jshint', {
cwd: 'C:\\workspace',
src: 'subfolder\\**\\*.js'
}, function (err, stdout, stderr) {
console.log(stdout);
var exitCode = 0;
if (err) {
console.log(stderr);
exitCode = -1;
}
process.exit(exitCode);
});
How can I pass params in execution time to my grunt task?
Thanks a lot, best regards.
Upvotes: 0
Views: 57
Reputation: 2121
If you want to pass command line parameters to grunt, you have to:
--paramName=value
grunt.option('paramName')
So in your case you would call
exec('grunt jshint --src=subfolder\\**\\*.js', {cwd: 'C:\\workspace'}, function (err, stdout, stderr) {...});
and you gruntfile would be:
jshint: {
(...)
src: [grunt.option('src')]
}
Upvotes: 1