Utilice la variable global para establecer la ruta de salida de compilación en Grunt
Tengo un par de tareas complicadas y estoy tratando de compartir variables globales a través de esas tareas y estoy teniendo problemas.
He escrito algunas tareas personalizadas que establecen la ruta de salida adecuada en función del tipo de compilación. Esto parece estar configurando las cosas correctamente.
// 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);
});
Por lo tanto, estoy intentando hacer referencia a global.outputPath en una tarea posterior y encontrar errores.
Si llamogrunt test
Desde la línea de comandos, genera la ruta correcta sin problemas.
Sin embargo, si tengo una tarea como esta: clean: {release: {src: global.outputPath}}
Lanza el siguiente error:Warning: Cannot call method 'indexOf' of undefined Use --force to continue.
Además, mis constantes en la tarea setOutput se establecen en la parte superior de mi archivo Gruntfile.js
¿Alguna idea? ¿Estoy haciendo algo mal aquí?