问题
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