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.
答案 0 :(得分:1)
如果要将命令行参数传递给grunt,则必须:
--paramName=value
grunt.option('paramName')
所以在你的情况下你会打电话给
exec('grunt jshint --src=subfolder\\**\\*.js', {cwd: 'C:\\workspace'}, function (err, stdout, stderr) {...});
你的gruntfile将是:
jshint: {
(...)
src: [grunt.option('src')]
}