0

For copying files to destination I am using simple gulp's src and dest

I want to specify this copy action as per key in obj:

    var copy = {
            first: {
                dest: 'dist/index.scala.html',
                src: 'app/index.scala.html'
            },
            second: {
                dest: 'dist/setup.scala.html',
                src: 'app/setup.scala.html'
            }
      };

I am able to create copy task and copy files as per src and dest mentioned in object But I need something like:

    gulp copy:first //this will only copy from src to dest as specifided under 'first' key

    gulp copy:second //this will only copy from src to dest as specifided under 'second' key

Like how we achieve in grunt.

Swapnil Dalvi
  • 999
  • 9
  • 23

1 Answers1

1

According to this article "it’s not possible to pass arguments on the command line which can be used by that task".

That said, you can do something like this:

const gulp = require("gulp");

const copy = {
    first: {
        dest: 'dist/index.scala.html',
        src: 'app/index.scala.html'
    },
    second: {
        dest: 'dist/setup.scala.html',
        src: 'app/setup.scala.html'
    }
};

for (let key in copy) {
    gulp.task('copy:' + key, cb => {
        console.log('copy[key]: ', copy[key]);
        cb();
    });
}

Note: I've changed copy = [...] to copy = {...} because arrays can't have strings (such as 'first') as keys but objects can.

Then to run the gulp commands:

gulp copy:first

gulp copy:second

You may also want to have a look at Pass Parameter to Gulp Task.

Rocky Sims
  • 3,523
  • 1
  • 14
  • 19