Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp doesn't copy all files as expected

Tags:

I tried to create a gulpfile.js for my personal website project. I've never done this before but with a little 'trial and error' it now works in an acceptable way.

The only thing that doesn't work even after 1000 modifications is simple copying files and folders.

var files = {
  data_src : [
    './files.json',
    'data/**/*.*'
  ],
  distribution_dest : '_distribution'
};

gulp.task('copy-data', function() {
  gulp.src(files.data_src, { base: './' })
    .pipe(gulp.dest(files.distribution_dest))
    .pipe(notify({message: 'Data copied for distribution!'}));
});

This should copy all sub-folders and files to the gulp.dest. But it copies only half of them, some folders will be ignored even if I change their names etc. (no special characters, same subfolder structure as the once that got copied correctly ...) - nothing worked. I just can't see any pattern in this.

There is no error message while running gulp. Nothing that would help me find the error.

Why are some folders or files excluded from copying?


I use base to keep the folder / sub-folder structure; tried with and without 'base' -> no effects on the copying process.

I also changed the position of the 'copy-data' task in the run-list. Actually it's the first task to run. There seems to be no change in behavior no matter if it's the first or the last one.

gulp.task('default', function() {
  gulp.run('copy-data', 'custom-sass', 'framework-sass', 'custom-js', 'framework-js', 'replace-tags', 'browser-sync');
    ... some watches ...
});

The structure of the data folder looks like these:

./data
   |-doc
   |---content
   |---template
   |-img
   |---chart
   |---icon
   |---logo
   |---pattern
   |---people
   |---photo
   |---symbol
   |-----brandklassen
   |-----brandschutzzeichen
   |-----gebotszeichen
   |-----gefahrensymbole
   |-----rettungszeichen
   |-----verbotszeichen
   |-----verkehrsrechtzeichen
   |-----warnzeichen
   |---wallpaper

/data/doc and all subfolders are ok.
/data/img/chart to /data/img/people are also ok.

Within /data/img/photo only 14 out of 21 images are copied.
/data/img/symbol with sub-folders and /data/img/wallpaper were ignored completely.

like image 593
Mountain Avatar asked Oct 19 '14 14:10

Mountain


1 Answers

SOLVED IT MYSELF! The problem was caused by async operating tasks. Adding a return forced gulp to complete the copying process before continuing!

gulp.task('copy-data', function() {
    return gulp.src(files.data_src, { base: './' })
    .pipe(gulp.dest(files.distribution_dest))
    .pipe(notify({message: 'Data copied for distribution!'}))
});

Now all images will be copied!

like image 163
Mountain Avatar answered Oct 01 '22 00:10

Mountain