I have several grunt tasks, and I'm trying to use global variables in these tasks, and I'm having problems.
I wrote some custom tasks that set the correct output path depending on the type of assembly. This seems to be correct.
// Set Mode (local or build) grunt.registerTask("setBuildType", "Set the build type. Either build or local", function (val) { // grunt.log.writeln(val + " :setBuildType val"); global.buildType = val; }); // SetOutput location grunt.registerTask("setOutput", "Set the output folder for the build.", function () { if (global.buildType === "tfs") { global.outputPath = MACHINE_PATH; } if (global.buildType === "local") { global.outputPath = LOCAL_PATH; } if (global.buildType === "release") { global.outputPath = RELEASE_PATH; } if (grunt.option("target")) { global.outputPath = grunt.option("target"); } grunt.log.writeln("Output folder: " + global.outputPath); }); grunt.registerTask("globalReadout", function () { grunt.log.writeln(global.outputPath); });
So, I'm trying to reference global.outputPath in the next task and errors.
If I call grunt test
from the command line, it gives the correct path without problems.
However, if I have such a task: clean: {release: {src: global.outputPath}}
It throws the following error: Warning: Cannot call method 'indexOf' of undefined Use --force to continue.
Also, my constants in the setOutput task are set at the top of my Gruntfile.js
Any thoughts? Am I something wrong here?
source share