Created
June 9, 2014 10:43
-
-
Save KATT/95a0ee406752a2212736 to your computer and use it in GitHub Desktop.
gulp task `open`
This file contains hidden or 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
var SERVER_PORT = 5000; | |
// Opens browser window using internal IP on the assigned SERVER_PORT | |
gulp.task('open', function() { | |
var os = require('os'); | |
var spawn = require('child_process').spawn | |
var interfaces = os.networkInterfaces(); | |
var addresses = []; | |
for (k in interfaces) { | |
for (k2 in interfaces[k]) { | |
var address = interfaces[k][k2]; | |
if (address.family == 'IPv4' && !address.internal) { | |
addresses.push(address.address) | |
} | |
} | |
} | |
var openAddress = addresses[0] || 'localhost'; | |
spawn('open', ['http://'+ openAddress + ':' + SERVER_PORT]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment