UPDATE
我目前正在使用类似于此处所述的错误通知解决方案,以及下面的"当前解决方法"(不修改grunt force选项)以获取成功通知.
原始问题
我无法确定grunt-contrib-watch运行的子任务何时完成(成功与否).
具体来说,我正在使用grunt-contrib-coffee和grunt watch来编译我们改变的CoffeeScript文件.编译工作正常.
我想做的是通知自己编译的状态.这是我尝试过的(CS中的所有代码):
来自SO问题(如果其子任务之一失败,如何使Grunt任务失败?)
我不喜欢的是:设置和恢复全局选项似乎很笨拙,特别是因为它发生在不同的任务/事件处理程序中.另外,我每次都要删除目标文件.
如果没有设置全局选项,我可以通知一个成功的编译,这很好,但我也想通知一个失败的编译.
grunt.initConfig
watch:
options: nospawn: true
coffee:
files: '<%= coffee.dev.cwd %>/<%= coffee.dev.src %>'
options:
events: ['changed', 'added']
coffee:
dev:
expand: true
cwd: 'app'
src: '**/*.coffee'
dest: 'public'
ext: '.js'
grunt.registerTask 'completedCompile', (srcFilePath, destFilePath) ->
grunt.option 'force', false
if grunt.file.exists( destFilePath )
# notify success
else
# notify failure
grunt.event.on 'watch', (action, filepath) ->
if grunt.file.isMatch grunt.config('watch.coffee.files'), filepath
filepath = # …Run Code Online (Sandbox Code Playgroud)