1

After reading this question, this package documentation and something about globs here, I cannot find the way to make the following code snippet to filter only the JavaScript files without their parent folders:

gulp.task("distribution", function () {

    return gulp.src("distribution/**/*.js", { nodir: true })

    .pipe(gulp.dest("www/javascripts"));

});

What I get is the following file structure:

javascripts/bootstrap/dist/js/bootstrap.js

javascripts/hammerjs/hammer.js

javascripts/jquery/dist/jquery.js

javascripts/localforage/dist/localforage.js

javascripts/moment/moment.js

javascripts/vue/dist/vue.js

javascripts/vue-touch/vue-touch.js

And what I want to get is the following file structure:

javascripts/bootstrap.js

javascripts/hammer.js

javascripts/jquery.js

javascripts/localforage.js

javascripts/moment.js

javascripts/vue.js

javascripts/vue-touch.js  

I've also try this code snippet with no result at all:

gulp.task("distribution", function () {

    const filterToApply = filter("*.js", { restore: true });

    return gulp.src("distribution/**")

    .pipe(filterToApply)

    .pipe(gulp.dest("www/javascripts"));

});

While this one give me the same result as the first one:

gulp.task("distribution", function () {

    const filterToApply = filter("**/*.js", { restore: true });

    return gulp.src("distribution/**")

    .pipe(filterToApply)

    .pipe(gulp.dest("www/javascripts"));

});
Community
  • 1
  • 1

1 Answers1

0

Try to pipe that filter with gulp-flatten by adding:

.pipe(flatten()) right before the gulp.dest pipe.

for example:

var flatten = require('gulp-flatten');

gulp.src('distribution/**/*.js')
  .pipe(flatten())
  .pipe(gulp.dest('"www/javascripts'));
Rogério Peixoto
  • 2,176
  • 2
  • 23
  • 31