grunt.util.spawn不提供输出

时间:2013-12-27 19:45:07

标签: coffeescript gruntjs

Grunt.util.spawn没有调用done函数。这是代码。当命令从命令提示符执行时它失败并抛出一条错误消息,该消息未在gruntjs中捕获......发生了什么

module.exports = (grunt)->
grunt.initConfig
    concurrent:
        dev: ['watch']
    slim:
        dev:
            expand: true
            src:  'views'
            dest: 'views/'
    watch:
        slim:
            files: 'views/**.slim'
            tasks:['slim']

grunt.registerMultiTask 'slim', 'Server Slim Compiler', ->
    console.log 'In the slim'
    options = {}
    options.cmd = 'dirld'
    options.grunt = true
    console.log options
    grunt.util.spawn options, (err,res,cod)->
        console.log 'in the spawn'
        if err
            grunt.log.error err
        else
            grunt.log.oklns 'success'
            grunt.log.writeln res

grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-concurrent'
grunt.registerTask 'default', ['concurrent:dev']

1 个答案:

答案 0 :(得分:5)

grunt.util.spawn是异步的,因此您需要使slim任务异步。请参阅:http://gruntjs.com/frequently-asked-questions#why-doesn-t-my-asynchronous-task-complete

grunt.registerMultiTask 'slim', 'Server Slim Compiler', ->
  done = @async()
  grunt.util.spawn options, (err,res,cod) ->
    done() # Im done, continue onto the next task