Would anyone know how to pass the current node version into grunt-exec? Currently I have grunt exec setup like the following:
grunt.initConfig({
exec:{
mocha: {
cmd:function(version){
if(semver.gt(version, '0.10')){
return 'mocha test/index.js';
} else return 'mocha --harmony test/harmony/index.js';
}
}
}
});
In grunt.registerTask()
, I have tried using a bash command like so
grunt.registerTask('default', [
'exec:mocha:$(node version)'
]);
but of course it doesn't work that way.
I have looked plugins such as grunt-node-version
but the lack of an actual example doesn't help much.
Any suggestions?
After looking up on npmjs.com, I found the perfect module that helped me do a little hack:
Using node-version, I was able to pass the version into the function and have semver decide if it's greater than a certain version like so:
var version = new (require('node-version').version);
version = version.getVersion();
grunt.initConfig({
exec:{
mocha: {
cmd:function(version){
if(semver.lt(version.toString(), '0.11.0')){
return 'mocha test/index.js';
} else return 'mocha --harmony test/harmony/index.js';
}
}
}
});
grunt.registerTask('default', [
'exec:mocha:' + version.long
]);