-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.js
executable file
·59 lines (47 loc) · 1.34 KB
/
cli.js
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
#!/usr/bin/env node
var optimist = require('optimist')
var Gateway = require('./')
var url = require('url')
process.title = 'remotedebug-gateway'
var argv = optimist
.usage('Usage: $0 url [options]')
.alias('b', 'browsers').describe('b', 'browsers to launch').default('b', 'canary')
.alias('p', 'port').describe('p', 'change the http port').default('p', 9000)
.describe('version', 'prints current version').boolean('boolean')
.argv
if (argv.version) {
console.error(require('./package').version)
process.exit(0)
}
var g = new Gateway({
httpPort: argv.port
})
Promise.delay = function (ms) {
return new Promise(function (r) {
setTimeout(r, ms)
})
}
if (argv.browsers) {
if(argv._[0]) {
url = url.format(url.parse(argv._[0]))
} else {
url = 'about:blank'
}
var allBrowser = argv.browsers.split(',').map(function (browserName) {
console.log('.. launching browsers:', browserName)
return g.api.launchBrowser(browserName, url).then(function (browserInfo) {
console.log('.. launched.', browserInfo)
return g.api.connect(browserInfo.debugUrl)
})
})
Promise.all(allBrowser).then(function () {
var target = g.api.findTargetByUrl(url)
if (target) {
process.stdout.write(target.devtoolsUrl)
}
})
}
process.on('SIGINT', function () {
g.api.closeOpenBrowsers()
process.exit()
})