/
app-inspector.js
executable file
·77 lines (59 loc) · 1.72 KB
/
app-inspector.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
69
70
71
72
73
74
75
76
77
#!/usr/bin/env node
'use strict';
const co = require('co');
const program = require('commander');
const update = require('npm-update');
const pkg = require('../package.json');
const _ = require('../lib/common/helper');
const logger = require('../lib/common/logger');
const {
chalk
} = _;
const Inspector = require('..');
const options = {
port: 5678,
verbose: true
};
const EOL = require('os').EOL;
program
.option('-p, --port <d>', 'port to use (5678 default)')
.option('-u, --udid <s>', 'udid of device')
.option('-s, --silent', 'start without opening browser')
.option('--verbose', 'show more debugging information')
.option('-v, --versions', 'output version infomation')
.usage('');
program.parse(process.argv);
var printInfo = function(lines) {
var maxLength = 0;
lines.forEach(line => {
maxLength = line.length > maxLength ? line.length : maxLength;
});
var res = [new Array(maxLength + 7).join('*')];
lines.forEach(line => {
res.push(`* ${line + new Array(maxLength - line.length + 1).join(' ')} *`);
});
res.push(new Array(maxLength + 7).join('*'));
console.log(chalk.white(`${EOL}${res.join(EOL)}${EOL}`));
};
// eslint-disable-next-line handle-callback-err
function init(error, data) {
if (data && data.version && pkg.version !== data.version) {
printInfo([`version ${pkg.version} is outdate`, `run: npm i -g ${pkg.name}@${data.version}`]);
}
if (program.versions) {
console.info(`${EOL} ${chalk.grey(pkg.version)} ${EOL}`);
process.exit(0);
}
if (!program.udid) {
program.help();
process.exit(0);
}
_.merge(options, _.getConfig(program));
co(Inspector, options).catch(e => {
console.log(e);
});
}
co(update, {
pkg: pkg,
callback: init
});