johnpapa / pluralsight-gulp

Starter Code for Pluralsight Course "JavaScript Build Automation with Gulp.js"
http://jpapa.me/gulpps
MIT License
158 stars 262 forks source link

Don't cleaning when i add the callback done. #24

Closed HectorLS closed 8 years ago

HectorLS commented 8 years ago

Hi, everything is working fine as you can see

gulp.task('styles', ['clean-styles'], function() {
  log('Compiling Less --> CSS');

  return gulp
    .src(config.lessInput)
    .pipe(less())
    .pipe(autoprefixer({browsers: ['last 2 versions', '> 5%']}))
    .pipe(gulp.dest(config.temp))
});

gulp.task('clean-styles', function() {
  var files = config.temp + '/**/*.css';
  clean(files);
});

function clean(path){
  log('Cleaning: ' + util.colors.blue(path));
  del(path);
}
▶ gulp styles
[11:59:06] Using gulpfile ~/pluralsight-gulp/gulpfile.js
[11:59:06] Starting 'clean-styles'...
[11:59:06] Cleaning: ./.tmp/**/*.css
[11:59:06] Finished 'clean-styles' after 8.29 ms
[11:59:06] Starting 'styles'...
[11:59:06] Compiling Less --> CSS
[11:59:07] Finished 'styles' after 201 ms

but i got this problem when i add the 'done' callback

gulp.task('styles', ['clean-styles'], function() {
  log('Compiling Less --> CSS');

  return gulp
    .src(config.lessInput)
    .pipe(less())
    .pipe(autoprefixer({browsers: ['last 2 versions', '> 5%']}))
    .pipe(gulp.dest(config.temp))
});

gulp.task('clean-styles', function(done) {
  var files = config.temp + '/**/*.css';
  clean(files, done);
});

function clean(path, done){
  log('Cleaning: ' + util.colors.blue(path));
  del(path, done);
}
▶ gulp styles
[12:02:21] Using gulpfile ~/pluralsight-gulp/gulpfile.js
[12:02:21] Starting 'clean-styles'...
[12:02:21] Cleaning: ./.tmp/**/*.css

Do you see ? the task stopped after log message :(

JeremyCarlsten commented 8 years ago

It looks like the del package was updated to remove the callback function, it now takes a promise. (https://github.com/sindresorhus/del/releases refer to the 2.0 release.)

I am trying to pass the promise in directly but gulp appears to not like that at all....

function clean(path, done) {
    log('cleaning: ' + $.util.colors.blue(path));
    del(path).then(done);
}

I was able to make it work, but I don't think it's very clean...

function clean(path, done) {
    log('cleaning: ' + $.util.colors.blue(path));
    del(path).then(function(){
        done();
    });
}

Thoughts?

HectorLS commented 8 years ago

Awesome ! it works! thank you man :) I think looks cleaner if you indent like this: (more lines but if you gonna have more than 1 promise its really helpful )

function clean(path, done) {
    log('cleaning: ' + $.util.colors.blue(path));
    del(path)
        .then(function(){
            done();
        });
}
jgcoding commented 8 years ago

If done as a promise, won't this work? It seems to be working for me with the new version for del del(path).then(done());

del(path, done()); was also successful