是否可以在监视任务后执行任务? [英] Is it possible to run a task after the watch task?
问题描述
我有一个基于PHP的项目,不能在 grunt-php 上运行。相反,我使用 grunt-exec 运行我的MAMP服务器进行开发。
exec:{
serverup:{
命令:'/Applications/MAMP/bin/start.sh'
},
serverdown:{
command:'/Applications/MAMP/bin/stop.sh'
}
}
在我的自定义开发任务中,我在监视任务之前运行MAMP启动脚本。然后,我试图在退出监视任务后停止MAMP服务器。
grunt.registerTask('default ',['jshint','concat','compass:dev','exec:serverup','watch','exec:serverdown']);
但是,如果我用Ctrl-C退出任务,则 exec: serverdown
任务似乎永远不会运行。有什么办法可以做到这一点?由于服务器永远不会关闭,因此该端口会一直关闭,直到我手动运行停止脚本,并且如果我在尝试再次运行默认任务之前再次运行停止脚本,则会收到错误。
如果没有,有没有其他的方法可以完成同样的事情? $ c $> SIGINT 并运行脚本:
var exec = require('child_process')。 EXEC;
process.on('SIGINT',function(){
exec('/ Applications / MAMP / bin / stop.sh',function(){
process.exit();
});
});
module.exports = function(grunt){};
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?
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) {};
这篇关于是否可以在监视任务后执行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!