Is it possible to run a task after the watch task?

冷暖自知 提交于 2019-12-10 17:08:57

问题


I have a PHP-based project that won't run on grunt-php. Instead, I use grunt-exec to run my MAMP server for development.

exec: {
  serverup: {
    command: '/Applications/MAMP/bin/start.sh'
  },
  serverdown: {
    command: '/Applications/MAMP/bin/stop.sh'
  }
}

In my custom development task, I run the MAMP start script just before my watch task. Then, I'm trying to stop the MAMP server after I've exited the watch task.

grunt.registerTask('default', ['jshint', 'concat', 'compass:dev', 'exec:serverup', 'watch', 'exec:serverdown']);

However, if I exit the task with Ctrl-C, the exec:serverdown task never seems to run. Is there any way to make this work? Since the server never goes down, that port is tied up until I manually run the stop script, and I get errors if I try to run the default task again before bringing it down.

If not, is there some other way I could accomplish the same thing?


回答1:


You could listen on SIGINT and run the script:

var exec = require('child_process').exec;
process.on('SIGINT', function () {
    exec('/Applications/MAMP/bin/stop.sh', function () {
        process.exit();
    });
});

module.exports = function (grunt) {};


来源:https://stackoverflow.com/questions/17710568/is-it-possible-to-run-a-task-after-the-watch-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!