Javascript 如何用del使用Gulp插件notify?
这应该很容易。。。我正在尝试创建一个del已完成的通知 德尔= 通知= 我有:Javascript 如何用del使用Gulp插件notify?,javascript,gulp,gulp-notify,Javascript,Gulp,Gulp Notify,这应该很容易。。。我正在尝试创建一个del已完成的通知 德尔= 通知= 我有: gulp.task('clean', function() { return del(['distFolder']); }); 这将在重新生成distFolder之前清除distFolder中的所有内容 我想做的事情如下: gulp.task('clean', function() { return del(['distFolder']).pipe(notify('Clean task finish
gulp.task('clean', function() {
return del(['distFolder']);
});
这将在重新生成distFolder之前清除distFolder中的所有内容
我想做的事情如下:
gulp.task('clean', function() {
return del(['distFolder']).pipe(notify('Clean task finished'));
});
上面返回了一个错误-“TypeError:del(…)。pipe不是函数”如果查看del模块,它不会返回流,因此将没有pipe函数(如错误所解释) 我可能会使用gulp clean,因为它可以更好地与gulp的流媒体集成 e、 g 解决它- 节点的通知程序是notify的依赖项。所以它应该已经在节点_模块中了。根据您的NPM版本,它可能不在根目录中 添加而不安装NPM-
var notifier=require('node-notifier')代码>
正确完成此任务的关键是del
返回承诺。所以你必须履行诺言
我创建了一个gulpfile,它有3个任务:
clean
演示了如何执行此操作
fail
说明了能够处理故障的意义
incorrect
复制中的方法,因为无论是否成功,del
都会返回承诺对象。因此,&&
测试将始终计算表达式的第二部分,因此将始终通知Clean Done代码>即使出现错误且未删除任何内容
代码如下:
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!'});
});
当你尝试你拥有的东西时会发生什么?@ColinMarshall-TypeError:del(…)。管道不是一个函数
gulp.task('clean', function(){
return del(dist) && notifier.notify({message:'Clean Done!'})
});
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!'});
});