1

In my gulpfile.js how do I correctly pass an array to gulp.src and iterate through it's contents? Here's my existing code that needs correcting:

const paths = {
    themes: [
        {
            name: 'cat',
            js: ['src/cat/js/**', 'src/cat/assets/js/**']
        },
        {
            name: 'dog',
            js: ['src/dog/js/**', 'src/dog/assets/js/**']
        }
    ],
    dist: {
        js: 'dist/js'
    }
}

gulp.task( 'theme:assets',
    function(done){
        paths.themes.forEach(function(theme){
            gulp.src(`${theme.js}`)
            .pipe(newer(paths.dist.js + '/' + `${theme.name}`))
            .pipe(gulp.dest(paths.dist.js + '/' + `${theme.name}`));
        });
        done();
    }
);
rjmoggach
  • 1,458
  • 15
  • 27
  • gulp.src() accepts array or a string, Could you paste the whole file. The line should look something like this gulp.src(['/assets/js/*.js']) – Daut Sep 11 '18 at 14:18
  • I want the input to come from the `paths` dict in this code snippet – rjmoggach Sep 11 '18 at 14:42
  • if i add `.split(',')` to the `${theme.js}` it works as expected... basically coercing the string into an object/array - but is there a better way??? – rjmoggach Sep 11 '18 at 15:14
  • Maybe you can't pass an array to `gulp.src`, this answer could help https://stackoverflow.com/a/21387311/4485780 – Ha Huu Tin Sep 11 '18 at 16:19
  • So your ${theme.js} is a string and adding .split(',') makes it an array. That is a pretty good way of doing it, no need to look for a 'better way' – Daut Sep 12 '18 at 08:35

0 Answers0