2014-11-05 45 views
1

我試圖在文件更改時運行shell命令。獲取上次更改的文件以用作shell命令的參數。代碼如下:'watch'eventListener更改文件名後的Grunt運行外殼

grunt.initConfig({ 
    changedFile: 'test', 

    watch: { 
     all: { 
      files: ['js/*.js'], 
      tasks: ['shell'] 
     } 
    }, 

    shell: { 
     run: { 
      // it outputs 'test', not changed file 
      command: 'touch <%= changedFile %>' 
     } 
    } 

}); 

grunt.event.on('watch', function(action, filepath) { 
    grunt.config('changedFile', filepath); 
}); 

'watch'eventListener實際上可以工作,但是它在shell命令運行後執行。如何在事件觸發前運行任務?

回答