/
helpers.js
74 lines (64 loc) · 1.71 KB
/
helpers.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
'use strict'
const decamelize = require('decamelize')
const schema = require('@istanbuljs/schema')
/* These options still need to be connected to the instrumenter
* Disabling them for now also avoids the issue with OSX cutting
* off the error help screen at 8192 characters.
*/
const blockOptions = [
'coverageVariable',
'coverageGlobalScope',
'coverageGlobalScopeFunc'
]
module.exports = {
setupOptions (yargs, command, cwd) {
Object.entries(schema.nyc.properties).forEach(([name, setup]) => {
if (blockOptions.includes(name)) {
return
}
const option = {
description: setup.description,
default: setup.default,
type: setup.type
}
if (name === 'cwd') {
if (command !== null) {
return
}
option.default = cwd
option.global = true
}
if (option.type === 'array') {
option.type = 'string'
}
if ('nycAlias' in setup) {
option.alias = setup.nycAlias
}
const optionName = decamelize(name, '-')
yargs.option(optionName, option)
if (!setup.nycCommands.includes(command)) {
yargs.hide(optionName)
}
})
},
/* istanbul ignore next: unsure how to test this */
suppressEPIPE (error) {
/* Prevent dumping error when `nyc npm t|head` causes stdout to
* be closed when reporting runs. */
if (error.code !== 'EPIPE') {
throw error
}
},
cliWrapper (execute) {
return argv => {
execute(argv).catch(error => {
try {
console.error(error.message)
} catch (_) {
/* We need to run process.exit(1) even if stderr is destroyed */
}
process.exit(1)
})
}
}
}