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 program = require('commander')
var path = require('path')
const nopt = require('nopt')
const config = nopt({ coverage: Boolean })
const configArray = ['s', 'serve', 'n', 'nodemon'].filter(item => config[item])
const coverageRequired = configArray.length >= 1
var istanbulMiddleware = require(path.resolve(__dirname, '..', 'lib/autoIstanbulLib/autoIstanbulHandlers.js'))
var { FRACTION_OF_COVERAGE_PORT_DATA } = istanbulMiddleware.globalVariable()
var exec = require('child_process').exec
var stopPm2 = `pm2 stop all`
const port = FRACTION_OF_COVERAGE_PORT_DATA
program
.option('-h --help', 'help information', helpInformation)
.option('-s --serve', 'start the service', serveInformation)
.option('-n --nodemon', 'close the service', nodemonInformation)
.option('-c --close', 'close the service', closeInformation)
.parse(process.argv);
function helpInformation() {
console.log('options:');
console.log('');
console.log('-s --serve start the service');
console.log('-n --nodemon start the service');
console.log('-c --close close the service');
console.log('');
};
function serveInformation() {
runSever()
}
function nodemonInformation() {
runSever()
}
function closeInformation() {
exec(stopPm2, (err, stdout, stderr) => {
if (err){
console.log(err);
console.warn(new Date(),' 代码覆盖率服务残留停止失败');
} else {
console.log(stdout);
console.warn(new Date(),' 代码覆盖率服务残留停止成功');
}
})
}
function runSever() {
if (coverageRequired) {
console.log('Turning on coverage; ensure this is not production')
istanbulMiddleware.hookLoader(__dirname, { verbose: true })
}
console.log('Starting server at: http://localhost:' + port)
if (!coverageRequired) {
console.log('Coverage NOT turned on, run with --coverage to turn it on')
}
require(path.resolve(__dirname, '..', 'lib/lstanbulabServer/index.js')).serve(port, coverageRequired)
}