wallet-core/node_modules/nyc/bin/nyc.js

102 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-05-28 00:38:50 +02:00
#!/usr/bin/env node
var configUtil = require('../lib/config-util')
var foreground = require('foreground-child')
var NYC
try {
NYC = require('../index.covered.js')
} catch (e) {
NYC = require('../index.js')
}
var processArgs = require('../lib/process-args')
var sw = require('spawn-wrap')
var wrapper = require.resolve('./wrap.js')
// parse configuration and command-line arguments;
// we keep these values in a few different forms,
// used in the various execution contexts of nyc:
// reporting, instrumenting subprocesses, etc.
2017-12-10 21:51:33 +01:00
var yargs = configUtil.addCommandsAndHelp(configUtil.buildYargs())
2017-05-28 00:38:50 +02:00
var instrumenterArgs = processArgs.hideInstrumenteeArgs()
var argv = yargs.parse(instrumenterArgs)
if (argv._[0] === 'report') {
2017-12-10 21:51:33 +01:00
// look in lib/commands/report.js for logic.
2017-05-28 00:38:50 +02:00
} else if (argv._[0] === 'check-coverage') {
2017-12-10 21:51:33 +01:00
// look in lib/commands/check-coverage.js for logic.
2017-05-28 00:38:50 +02:00
} else if (argv._[0] === 'instrument') {
// look in lib/commands/instrument.js for logic.
} else if (argv._.length) {
// if instrument is set to false,
// enable a noop instrumenter.
2017-12-10 21:51:33 +01:00
if (!argv.instrument) argv.instrumenter = './lib/instrumenters/noop'
else argv.instrumenter = './lib/instrumenters/istanbul'
2017-05-28 00:38:50 +02:00
2017-12-10 21:51:33 +01:00
var nyc = (new NYC(argv))
if (argv.clean) {
2017-10-14 18:40:54 +02:00
nyc.reset()
} else {
nyc.createTempDirectory()
}
2017-12-10 21:51:33 +01:00
if (argv.all) nyc.addAllFiles()
2017-05-28 00:38:50 +02:00
var env = {
2017-12-10 21:51:33 +01:00
NYC_CONFIG: JSON.stringify(argv),
2017-05-28 00:38:50 +02:00
NYC_CWD: process.cwd(),
NYC_ROOT_ID: nyc.rootId,
2017-12-10 21:51:33 +01:00
NYC_INSTRUMENTER: argv.instrumenter
2017-05-28 00:38:50 +02:00
}
2017-12-10 21:51:33 +01:00
if (argv['babel-cache'] === false) {
2017-05-28 00:38:50 +02:00
// babel's cache interferes with some configurations, so is
// disabled by default. opt in by setting babel-cache=true.
env.BABEL_DISABLE_CACHE = process.env.BABEL_DISABLE_CACHE = '1'
}
sw([wrapper], env)
// Both running the test script invocation and the check-coverage run may
// set process.exitCode. Keep track so that both children are run, but
// a non-zero exit codes in either one leads to an overall non-zero exit code.
process.exitCode = 0
foreground(processArgs.hideInstrumenterArgs(
// use the same argv descrption, but don't exit
// for flags like --help.
configUtil.buildYargs().parse(process.argv.slice(2))
), function (done) {
var mainChildExitCode = process.exitCode
2017-12-10 21:51:33 +01:00
if (argv.checkCoverage) {
checkCoverage(argv)
2017-05-28 00:38:50 +02:00
process.exitCode = process.exitCode || mainChildExitCode
2017-12-10 21:51:33 +01:00
if (!argv.silent) report(argv)
2017-05-28 00:38:50 +02:00
return done()
} else {
2017-12-10 21:51:33 +01:00
if (!argv.silent) report(argv)
2017-05-28 00:38:50 +02:00
return done()
}
})
} else {
// I don't have a clue what you're doing.
yargs.showHelp()
}
function report (argv) {
process.env.NYC_CWD = process.cwd()
var nyc = new NYC(argv)
nyc.report()
}
function checkCoverage (argv, cb) {
process.env.NYC_CWD = process.cwd()
;(new NYC(argv)).checkCoverage({
lines: argv.lines,
functions: argv.functions,
branches: argv.branches,
statements: argv.statements
2017-08-14 05:01:11 +02:00
}, argv['per-file'])
2017-05-28 00:38:50 +02:00
}