Q:

Gulp pipe creating files and using those files

I'm playing with gulp and I stumbled on this issue that I can't really understand. 
I have some tasks:
gulp.task('concat-js', (done) => {
  gulp.src('src/app/**/*.js')
    .pipe(concat('app-script.js'))
    .pipe(gulp.dest('src/app/dist/'));

  done();
});

gulp.task('minify-js', (done) => {
  gulp.src('src/app/dist/*.js')
    .pipe(minify({noSource: true, ignoreFiles: ['*-min.js']}))
    .pipe(gulp.dest('src/app/dist/'));

  done();
});

gulp.task('compress',
  gulp.series('concat-js', 'minify-js', function(done) {
    // default task code here
    done();
  })
);

gulp.task(
  'run',
  gulp.series('compress', () => {
  ...
  }
));

My goal is that when run is executed, I get concatenated of my source files and then minifed version of that file. But I'm running in some kind of problem with executing those tasks in series.
When I execute run for the first time, application doesn't run and only app-script.js gets created. Running it for the second time creates app-script-min.js file.
As far as I understand minify-js doesn't wait for concat-js to finish creating file.

A:

I think this might be because done() is called before gulp is completed. Try change
gulp.task('concat-js', (done) => {
  gulp.src('src/app/**/*.js')
    .pipe(concat('app-script.js'))
    .pipe(gulp.dest('src/app/dist/'));

  done();
});

to
gulp.task('concat-js', (done) => {
  gulp.src('src/app/**/*.js')
    .pipe(concat('app-script.js'))
    .pipe(gulp.dest('src/app/dist/'))
    .on('finish', function() {
        done();
    });

});

I also found this resource which might be interesting for you. http://www.ericcredeur.com/gulp/javascript/2015/07/15/cascading-gulp-tasks.html

