UNPKG

1.32 kBJavaScriptView Raw
1#!/usr/bin/env node
2'use strict'
3
4const foreground = require('foreground-child')
5const { outputReport } = require('../lib/commands/report')
6const { promises } = require('fs')
7const { promisify } = require('util')
8const rimraf = require('rimraf')
9const {
10 buildYargs,
11 hideInstrumenteeArgs,
12 hideInstrumenterArgs
13} = require('../lib/parse-args')
14
15const instrumenterArgs = hideInstrumenteeArgs()
16let argv = buildYargs().parse(instrumenterArgs)
17
18async 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 // fs.promises was not added until Node.js v10.0.0, if it doesn't
25 // exist, assume we're Node.js v8.x and skip coverage.
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
49run().catch((err) => {
50 console.error(err.stack)
51 process.exitCode = 1
52})