1

Can't get the right solution with Grunt JS task runner, so here is my question.

Goal : duplicate a task a number of times. The number of times is the length of an Array.In the array, there are "names" which I use to build the paths ( sources and destinations ) to copy files over folders.

I am trying this with the copy task ( grunt-contrib-copy ).

I am able to get datas to the copy task but not in the right places : src are empty sometimes and wrong other times.The same for the dest folder.

I suspect something wrong with my Javascript or then it is just not possible to achieve that ( passing those parameters to grunt copy task or other tasks .. )

    grunt.config(['copy'], {
  themeCss : {
      files: (function() {
        var arr = ["site1","site2","site3"];
        var out = {};
        arr.forEach(function (element, index){
          var src = 'srcfolder/' + arr[index] + '/theme.css';
          var dest = 'destfolder/' + arr[index];
          out[src] = src;
          out[dest] = dest;
        });
          return out;
      }())
    },
}),
Klark
  • 31
  • 7

1 Answers1

2

I was looking for almost exactly the same this when I found your question. With some tweaks I got it working. Try this:

grunt.config(['copy'], {
   themeCss : {
      files: (function() {
         var arr = ["site1","site2","site3"];
         var out = [];
         arr.forEach(function (element, index){
            var src = 'srcfolder/' + arr[index] + '/theme.css';
            var dest = 'destfolder/' + arr[index];
            out.push({
               src: src,
               dest: dest
            });
         });
         return out;
      })()
   }
})
more cowbell
  • 101
  • 1
  • 7