forked from wuchangming/spy-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (54 loc) · 2 KB
/
index.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
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
'use strict';
var program = require('commander');
var weinreDelegate = require('./weinre/weinreDelegate');
var colors = require('colors');
var http = require('http');
program.version(require('../package.json').version).option('-p, --port [value]', 'start port').option('-i, --showIframe [value]', 'spy iframe window').option('-b, --autoDetectBrowser [value]', 'Auto detect Browser Request').option('-e, --externalProxy [value]', 'set external Proxy').option('-c, --cache [value]', 'set no cache').option('-w, --contentEditable [value]', 'set content editable');
program.parse(process.argv);
var cusSpyProxyPort = program.port || 9888;
var cusShowIframe = false;
if (program.showIframe === 'true') {
cusShowIframe = true;
}
var autoDetectBrowser = true;
if (program.autoDetectBrowser === 'false') {
autoDetectBrowser = false;
}
var cusCache = false;
if (program.cache === 'true') {
cusCache = true;
}
var cusContentEditable = false;
if (program.contentEditable === 'true') {
cusContentEditable = true;
}
weinreDelegate.createCA();
var tempServer = new http.Server();
var createTempServerPromise = function createTempServerPromise(port) {
return new Promise(function (resolve, reject) {
tempServer.listen(port, function () {
tempServer.close(function () {
resolve();
});
});
tempServer.on('error', function (e) {
console.error(colors.red('警告:启动失败', e));
console.error(colors.red('检查端口' + port + '是否被占用'));
reject(e);
});
});
};
var tempServerPromise = createTempServerPromise(cusSpyProxyPort);
tempServerPromise.then(function () {
weinreDelegate.run({
cusExternalProxy: program.externalProxy,
cusSpyProxyPort: cusSpyProxyPort,
cusShowIframe: cusShowIframe,
cusAutoDetectBrowser: autoDetectBrowser,
cusCache: cusCache,
cusContentEditable: cusContentEditable
});
}, function (e) {
throw e;
});