2015-12-20 13 views
6

To powinno być łatwe ... Próbuję utworzyć powiadomienie o zakończeniu del.Jak korzystać z wtyczki Gulp powiadom z del?

Del = https://www.npmjs.com/package/del

Informuj = https://www.npmjs.com/package/gulp-notify

mam:

gulp.task('clean', function() { 
    return del(['distFolder']); 
}); 

To ściąga wszystko w distFolder zanim zostanie odbudowany.

Co staram się zrobić coś jak poniżej:

gulp.task('clean', function() { 
    return del(['distFolder']).pipe(notify('Clean task finished')); 
}); 

powyższych zwraca błąd - „Błąd typu:. Del (...) rura nie jest funkcją”

+0

Co się dzieje podczas próby, co masz? –

+0

@ColinMarshall - TypeError: del (...). Pipe nie jest funkcją – RooksStrife

Odpowiedz

3

Kluczem do coraz to zrobione dobrze, że del zwraca obietnicę. Więc musisz obsłużyć obietnicę.

Utworzyłem gulpfile że ma 3 zadania:

  1. clean ilustruje w jaki sposób to zrobić.

  2. fail ilustruje punkt, w którym można poradzić sobie z awariami.

  3. incorrect replikuje metody w OP's self-answer To jest błędne, ponieważ del zwraca obiekt obietnica, czy nie uda się. Tak więc test && zawsze oceni drugą część wyrażenia, a zatem zawsze będzie powiadamiał Clean Done!, nawet jeśli wystąpił błąd i nic nie zostało usunięte.

Oto kod:

var gulp = require("gulp"); 
var notifier = require("node-notifier"); 
var del = require("del"); 

// This is how you should do it. 
gulp.task('clean', function(){ 
    return del("build").then(function() { 
     notifier.notify({message:'Clean Done!'}); 
    }).catch(function() { 
     notifier.notify({message:'Clean Failed!'}); 
    }); 
}); 

// 
// Illustrates a failure to delete. You should first do: 
// 
// 1. mkdir protected 
// 2. touch protected/foo.js 
// 3. chmod a-rwx protected 
// 
gulp.task('fail', function(){ 
    return del("protected/**").then (function() { 
     notifier.notify({message:'Clean Done!'}); 
    }).catch(function() { 
     notifier.notify({message:'Clean Failed!'}); 
    }); 
}); 

// Contrary to what the OP has in the self-answer, this is not the 
// correct way to do it. See the previous task for how you must setup 
// your FS to get an error. This will fail to delete anything but 
// you'll still get the "Clean Done" message. 
gulp.task('incorrect', function(){ 
    return del("protected/**") && notifier.notify({message:'Clean Done!'}); 
}); 
1

Jeśli spójrz na moduł Del, który nie zwraca strumienia, więc nie będzie funkcji rury (jak wyjaśnia błąd).

Prawdopodobnie użyłbym gulp-clean, ponieważ lepiej integruje się z transmisją gulpów.

np.

var clean = require('gulp-clean'); 
var notify = require('gulp-notify'); 

gulp.task('clean', function() { 
    return gulp.src('distFolder', {read: false}) 
     .pipe(clean()) 
     .pipe(notify('Clean task finished')); 
}); 
0

rozwiązać go -

zgłaszający węzeł jest zależność od zawiadomić. Powinien być już w module node_modules. W zależności od wersji NPM może nie znajdować się w katalogu głównym.

Dodaj bez KMP instalacja - var notifier = require('node-notifier');

gulp.task('clean', function(){ 
    return del(dist) && notifier.notify({message:'Clean Done!'}) 
}); 
Powiązane problemy