gruntjs - How to use dynamic values in Grunt tasks called from inside a forEach? -
we trying run grunt tasks using grunt.config.set dynamically concatinated strings. these grunt.configs set in foreach loop , change each time before task run.
this unfortunately not work, grunt uses last grunt.config.set , runs multiple times same value.
see example simple "copy" task ("copy" example, want use kind of dynamic options in other tasks, too):
copy: { projectfiles : { files : [{ src: 'src/<%= directoryname %>/*', dest: 'build/<%= directoryname %>/*' }] } } grunt.registertask('copyfiles', function() { var projects = ['directory1','directory2','directory3','directory4']; projects.foreach(function(project){ grunt.config.set("directoryname", project); grunt.task.run('copy:projectfiles'); }); }); this tasks copies 4 times src/directory4.
is somehow possible build kind of tasks use dynamic values? nice, other solution copy each task multiple times static strings.
thank you! daniel
the issue grunt.task.run not run task immediately, pushes list of tasks run later, while grunt.config.set executes immediately. end list of 4 times same task execute.
you can want defining different targets dynamically, running them, below:
grunt.registertask('copyfiles', function() { var projects = ['directory1','directory2','directory3','directory4']; projects.foreach(function(project){ grunt.config.set("copy." + project, { files : [{ src: 'src/' + project + '/*', dest: 'build/' + project + '/' }] }); grunt.task.run('copy:' + project); }); });
Comments
Post a Comment