/bio/skills/blog/math

Gulp Clean

Here’s a useful (semi-useless) discovery. To get gulp tasks to execute synchronously, we need to return the gulp stream at the end of each task so they can pass onto an implicit promise. Dave Lenny has a nice example of this.

gulp.task('default', ['one', 'two', 'three']);

Tasks one, two, and three should all return gulp streams. Eg:

gulp.task('one', () => {
  // fuim
  return gulp.src('file')
    .pipe($.itReallyIsMagic());
});

gulp.task('two', () => {
  // fuim
  return gulp.src('file')
    .pipe($.iSwearItsMagic());
});

gulp.task('three', () => {
  // fuim
  return gulp.src('file')
    .pipe($.actualWizardsMadeThis());
});

I realized my gulp clean task was simply:

gulp.task('clean' () => {
  return del(['dir1', 'dir2']);
});

which is basically the end of the world since del is not a gulp stream. So I started using gulp-clean (npm install --save-dev gulp-clean) and my gulp task has re-gifted me a pipe so that Mario, Luigi, plumbing metaphor….

gulp.task('clean' () => {
  return gulp.src(['.tmp', 'dist'], {read: false})
    .pipe($.clean());
});
2025 Stefano De Vuono