-
Notifications
You must be signed in to change notification settings - Fork 91
/
c8.js
executable file
·46 lines (41 loc) · 1.12 KB
/
c8.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
#!/usr/bin/env node
'use strict'
const foreground = require('foreground-child')
const { outputReport } = require('../lib/commands/report')
const mkdirp = require('mkdirp')
const { promisify } = require('util')
const rimraf = require('rimraf')
const {
buildYargs,
hideInstrumenteeArgs,
hideInstrumenterArgs
} = require('../lib/parse-args')
const instrumenterArgs = hideInstrumenteeArgs()
let argv = buildYargs().parse(instrumenterArgs)
async function run () {
if ([
'check-coverage', 'report'
].indexOf(argv._[0]) !== -1) {
argv = buildYargs(true).parse(process.argv.slice(2))
} else {
if (argv.clean) {
await promisify(rimraf)(argv.tempDirectory)
}
// allow c8 to run on Node 8 (coverage just won't work).
await promisify(mkdirp)(argv.tempDirectory)
process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), async (done) => {
try {
await outputReport(argv)
} catch (err) {
console.error(err.stack)
process.exitCode = 1
}
done()
})
}
}
run().catch((err) => {
console.error(err.stack)
process.exitCode = 1
})