2016-07-25 44 views
0

我知道我可以使用node-notifier但有沒有更好的方式來建立一個通知,它依賴於一個任務是完整的(和不使用.pipe)一飲而盡通知取決於任務完成不.pipe

下面的工作,但有一種方法可以在一個任務內完成這個任務嗎?

// Perform data task 
gulp.task('imgData1', function() { 
    imageExport.record({ 
    path: path.images_src, 
    output: path.images_data, 
    template: 'custom.hbs', 
    breakpointDelimiter: '--' 
    }) 
}); 

// Perform notification task 
gulp.task('imgData2', ['imgData1'], function() { 
    notifier.notify({ 
    'title': 'My notification', 
    'message': 'Data task complete!' 
}); 
}); 

// Perform data task then the notification task 
gulp.task('imgData', ['imgData2']); 

回答

1

image-size-exportaccepts a callbackimageExport.record()結束時調用。在該回調中只需運行notifier.notify()

gulp.task('imgData', function() { 
    imageExport.record({ 
    path: path.images_src, 
    output: path.images_data, 
    template: 'custom.hbs', 
    breakpointDelimiter: '--' 
    }, function() { 
    notifier.notify({ 
     'title': 'My notification', 
     'message': 'Data task complete!' 
    }); 
    }); 
}); 
+0

謝謝Sven。我確實給了這個提示,但得到了一個錯誤:'var tpl = template.toString();' - TypeError:無法讀取未定義的屬性'toString'。將再看一次。 – fivedoor

+0

這是[此行](https://github.com/Sebastian-Fitzner/image-size-export/blob/e13dba47c3f9f52851e4f904611a26e6d7955cff/lib/imagesizeExport.js#L148)。可能意味着'custom.hbs'文件由於某種原因無法讀取(路徑錯誤?)。 –

+0

啊,這是有道理的。對,就是這樣。我當時是一個eedyat,並沒有正確更新我的文件路徑。現在完美工作。謝謝你的幫助! – fivedoor