365af07706ded44857c93f2a346399ba85dc46ec.svn-base
1.7 KB
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
'use strict'
const fs = require('fs')
const path = require('path')
const makeDir = require('make-dir')
const NYC = require('../../index.js')
exports.command = 'merge <input-directory> [output-file]'
exports.describe = 'merge istanbul format coverage output in a given folder'
exports.builder = function (yargs) {
return yargs
.demandCommand(0, 0)
.positional('input-directory', {
describe: 'directory containing multiple istanbul coverage files',
type: 'text',
default: './.nyc_output'
})
.positional('output-file', {
describe: 'file to output combined istanbul format coverage to',
type: 'text',
default: 'coverage.json'
})
.option('temp-dir', {
alias: 't',
describe: 'directory to read raw coverage information from',
default: './.nyc_output'
})
.option('temp-directory', {
hidden: true
})
.example('$0 merge ./out coverage.json', 'merge together reports in ./out and output as coverage.json')
}
exports.handler = function (argv) {
process.env.NYC_CWD = process.cwd()
const nyc = new NYC(argv)
let inputStat
try {
inputStat = fs.statSync(argv.inputDirectory)
if (!inputStat.isDirectory()) {
console.error(`${argv.inputDirectory} was not a directory`)
process.exit(1)
}
} catch (err) {
console.error(`failed access input directory ${argv.inputDirectory} with error:\n\n${err.message}`)
process.exit(1)
}
makeDir.sync(path.dirname(argv.outputFile))
const map = nyc.getCoverageMapFromAllCoverageFiles(argv.inputDirectory)
fs.writeFileSync(argv.outputFile, JSON.stringify(map, null, 2), 'utf8')
console.info(`coverage files in ${argv.inputDirectory} merged into ${argv.outputFile}`)
}