-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun_nv
More file actions
executable file
·61 lines (58 loc) · 1.86 KB
/
run_nv
File metadata and controls
executable file
·61 lines (58 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
var launch = require('launchpad')
, static = require('node-static')
, directory = './public'
, port = 8000
, url = 'http://localhost:' + port + '/'
// Create a node-static server instance to serve the './public' folder
var file = new static.Server(directory)
require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response)
}).resume()
}).listen(port)
console.log('Server listening on port', port)
// Try to launch a local browser
launch.local(function(err, local) {
if (err) {
console.error('error launching browser: ' + err)
console.log('open a web browser at ' + url)
return
}
var browsers = local.browsers
, chrome = false
, safari = false
, firefox = false
if (typeof browsers === null || browsers.length <= 0) {
console.warn('No browsers found; get chrome: http://chrome.com')
console.log('Open a web browser at ' + url)
return
}
for (var i = 0 ; i < browsers.length; i++) {
if (browsers[i].browser === 'chrome') chrome = true
if (browsers[i].browser === 'safari') safari = true
if (browsers[i].browser === 'firefox') firefox = true
}
if (safari) {
console.log('Launching safari')
local.safari(url, function(err, instance) {
if (err) console.error('unable to launch safari: ' + err)
})
}
else if (chrome) {
console.log('Launching chrome')
local.chrome(url, function(err, instance) {
if (err) console.error('unable to launch chrome: ' + err)
})
}
else if (firefox) {
console.log('Launching firefox')
local.firefox(url, function(err, instance) {
if (err) console.error('unable to launch firefox: ' + err)
})
}
else {
console.warn('No appropriate browsers found; get chrome: http://chrome.com')
console.log('Open a web browser at ' + url)
}
})