1 | #!/usr/bin/env node
|
2 | 'use strict'
|
3 |
|
4 | const foreground = require('foreground-child')
|
5 | const { outputReport } = require('../lib/commands/report')
|
6 | const { promises } = require('fs')
|
7 | const { promisify } = require('util')
|
8 | const rimraf = require('rimraf')
|
9 | const {
|
10 | buildYargs,
|
11 | hideInstrumenteeArgs,
|
12 | hideInstrumenterArgs
|
13 | } = require('../lib/parse-args')
|
14 |
|
15 | const instrumenterArgs = hideInstrumenteeArgs()
|
16 | let argv = buildYargs().parse(instrumenterArgs)
|
17 |
|
18 | async function run () {
|
19 | if ([
|
20 | 'check-coverage', 'report'
|
21 | ].indexOf(argv._[0]) !== -1) {
|
22 | argv = buildYargs(true).parse(process.argv.slice(2))
|
23 | } else {
|
24 |
|
25 |
|
26 | if (!promises) {
|
27 | foreground(hideInstrumenterArgs(argv))
|
28 | return
|
29 | }
|
30 |
|
31 | if (argv.clean) {
|
32 | await promisify(rimraf)(argv.tempDirectory)
|
33 | }
|
34 |
|
35 | await promises.mkdir(argv.tempDirectory, { recursive: true })
|
36 | process.env.NODE_V8_COVERAGE = argv.tempDirectory
|
37 | foreground(hideInstrumenterArgs(argv), async (done) => {
|
38 | try {
|
39 | await outputReport(argv)
|
40 | } catch (err) {
|
41 | console.error(err.stack)
|
42 | process.exitCode = 1
|
43 | }
|
44 | done()
|
45 | })
|
46 | }
|
47 | }
|
48 |
|
49 | run().catch((err) => {
|
50 | console.error(err.stack)
|
51 | process.exitCode = 1
|
52 | })
|