Created
April 10, 2017 15:57
-
-
Save brianpkelley/b05979b2b5c017e6b6558eeb2f261590 to your computer and use it in GitHub Desktop.
Kill livereload servers on Gulp run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Credit to https://danisadesigner.com/blog/killing-livereload-server/ for the initial command (and a handy bash script) | |
*/ | |
const gulp = require('gulp'); | |
const exec = require('child_process').exec; | |
const livereload = require('gulp-livereload'); | |
// YOUR INCLUDES HERE! | |
module.exports = function () { | |
// Kill any running liverload server... sorry if you got more than one running :-P | |
exec( | |
'LRPID=$(/usr/sbin/lsof -n -i4TCP:35729 | grep LISTEN | awk \'{print $2}\'); echo $LRPID; if [ $LRPID ]; then kill -9 $LRPID; fi', | |
function( err, stdout, stderr ) { /* jshint ignore:line */ | |
if ( stdout ) { | |
console.log("Starting Listener"); | |
} | |
if ( stderr ) { | |
console.error( stderr ); | |
} | |
livereload.listen(); | |
// Dummy... change this. | |
// gulp.watch(..., [...]); | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment