I use grunt to do some tasks every time I change my code (like jshint) and I want to restart the phantomJs process every time I have changes.
The first way I found is to use grunt.util.spawn to launch phantomJs for the first time.
// http://gruntjs.com/api/grunt.util#grunt.util.spawn var phantomJS_child = grunt.util.spawn({ cmd: './phantomjs-1.9.1-linux-x86_64/bin/phantomjs', args: ['./phantomWorker.js'] }, function(){ console.log('phantomjs done!'); // we never get here... });
And then, every time the clock restarts, another task uses grunt.util.spawn to kill the phantomJs process, which, of course, is VERY ugly.
Is there a better way to do this? The fact is that the phantomJs process is not thematic, because I use it as a web server for a REST API server with JSON.
Can I have a callback or something else when the clock fires, so I can close my previous phantomJs process before starting the task again to create a new one?
I used grunt.event to create a handler, but I donβt see how to access the phantomjs process to kill it.
grunt.registerTask('onWatchEvent',function(){ // whenever watch starts, do this... grunt.event.on('watch',function(event, file, task){ grunt.log.writeln('\n' + event + ' ' + file + ' | running-> ' + task); }); });
source share