2

Have a super simple gulp file where I want to run some basic gulp tasks in sequence one after the other.

I can't seem to get this running in Gulp v4. Had something similar in Gulp v3 using run-sequence instead of gulp.series()

const gulp = require("gulp");
const clean = require('gulp-clean');

gulp.task('clean-app', async () => {
  return (gulp.src('./dist/app', {read: true, allowEmpty: true})
    .pipe(clean()));
});


gulp.task('clean-tests', async () => {
  return ( gulp.src('./dist/tests', {read: true, allowEmpty: true})
    .pipe(clean()));
});

gulp.task('all-tasks', gulp.series('clean-app', 'clean-tests'));

The individual gulp tasks clean-app and clean-tests run fine individually.

However, when I use gulp all-tasks i get the below error

gulp all-tasks
[17:50:51] Using gulpfile ~\IdeaProjects\my-app\gulpfile.js
[17:50:51] Starting 'all-tasks'...
[17:50:51] Starting 'clean-app'...
[17:50:51] Finished 'clean-app' after 10 ms
[17:50:51] The following tasks did not complete: all-tasks
[17:50:51] Did you forget to signal async completion?

Both clean-app and clean-tests return streams which I thought would be sufficient.

Have tried using gulp4-run-sequence but i get the same error.

Want to be able to run gulp all-tasks such that clean-tests is executed after clean-app has completed successfully.

user805703
  • 207
  • 6
  • 14

1 Answers1

5

depending on the official documents here try to run cb() in your tasks like that

const gulp = require("gulp");
const clean = require('gulp-clean');

gulp.task('clean-app', (cb) => {
  gulp.src('./dist/app', {read: true, allowEmpty: true}).pipe(clean());
  cb();
});

gulp.task('clean-tests', (cb) => {
  gulp.src('./dist/tests', {read: true, allowEmpty: true}).pipe(clean());
  cb();
});

gulp.task('all-tasks', gulp.series('clean-app', 'clean-tests'));
Muho
  • 3,188
  • 23
  • 34
  • tried using that @mohammad-altenji that but still gives the same error. Starting to wonder if there's some bug in the gulp-clean module im using – user805703 Apr 30 '19 at 08:54
  • try to remove the clean() function and gulp-clean module to check if there is something will change! – Muho Apr 30 '19 at 19:47
  • This worked great for me as a quick dirty fix for a project where I needed to move to gulp4 (using gulp4-run-sequence) – jameslol Aug 10 '20 at 03:11
  • how can i run only one task on demand, for example `>gulp clearn-app` – sairfan Jul 07 '22 at 20:45