diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e8a9d1b..b4ac7430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - 2.7.11 - fixed type style for UI - fixed string to multiple patterns "{...}" for minimatch filter + - added `--all` option for CLI - added README.zh-Hans.md - 2.7.10 diff --git a/README.md b/README.md index 642d521b..4b33d971 100644 --- a/README.md +++ b/README.md @@ -703,32 +703,7 @@ npx mcr node ./test/specs/node.test.js -r v8,console-details --lcov ``` - CLI Options -```sh -Usage: mcr [options] [command] - -CLI to generate coverage reports - -Arguments: - command command to execute - -Options: - -v, --version output the current version - -c, --config custom config file path - -l, --logging off, error, info, debug - -n, --name report name for title - -r, --reports coverage reports to use - -o, --outputDir output dir for reports - -i, --inputDir input dir for merging raw files - --entryFilter entry url filter - --sourceFilter source path filter - --outputFile output file for v8 report - --inline inline html for v8 report - --assetsPath assets path if not inline - --lcov generate lcov.info file - --import preload module at startup - --require preload module at startup - -h, --help display help for command -``` +see all options with running `mcr` or `mcr --help` - Use `--` to separate sub CLI args ```sh diff --git a/README.zh-Hans.md b/README.zh-Hans.md index 996e3821..8f232dfd 100644 --- a/README.zh-Hans.md +++ b/README.zh-Hans.md @@ -706,32 +706,7 @@ npx mcr node ./test/specs/node.test.js -r v8,console-details --lcov ``` - 命令行参数 -```sh -Usage: mcr [options] [command] - -CLI to generate coverage reports - -Arguments: - command command to execute - -Options: - -v, --version output the current version - -c, --config custom config file path - -l, --logging off, error, info, debug - -n, --name report name for title - -r, --reports coverage reports to use - -o, --outputDir output dir for reports - -i, --inputDir input dir for merging raw files - --entryFilter entry url filter - --sourceFilter source path filter - --outputFile output file for v8 report - --inline inline html for v8 report - --assetsPath assets path if not inline - --lcov generate lcov.info file - --import preload module at startup - --require preload module at startup - -h, --help display help for command -``` +直接运行 `mcr` 或 `mcr --help` 查看所有CLI的参数 - 使用 `--` 可以隔离子程序参数,以免两种参数混淆 ```sh diff --git a/lib/cli.js b/lib/cli.js index 987a3af1..5d9ddd13 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -193,6 +193,8 @@ program .option('-o, --outputDir ', 'output dir for reports') .option('-i, --inputDir ', 'input dir for merging raw files') + .option('-a, --all ', 'include all files from dir') + .option('--entryFilter ', 'entry url filter') .option('--sourceFilter ', 'source path filter') diff --git a/lib/converter/converter.js b/lib/converter/converter.js index a1b37d8b..26450610 100644 --- a/lib/converter/converter.js +++ b/lib/converter/converter.js @@ -955,7 +955,7 @@ const getSourceFilter = (options) => { // string to multiple patterns "{...}" // mcr npx mocha --sourceFilter {'**/node_modules/**':false,'**/src/*.js':true} // mcr npx mocha --sourceFilter "{'**/node_modules/**': false, '**/src/*.js': true}" - const obj = Util.strToObjPatterns(input); + const obj = Util.strToObj(input); if (obj) { input = obj; } else { diff --git a/lib/generate.js b/lib/generate.js index ee9ce06e..0c7b2c7d 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -502,7 +502,7 @@ const resolveAllFilter = (input) => { // for single minimatch pattern if (input && typeof input === 'string') { // string to multiple patterns "{...}" - const obj = Util.strToObjPatterns(input); + const obj = Util.strToObj(input); if (obj) { input = obj; } else { @@ -549,9 +549,18 @@ const resolveAllOptions = (input, dataList) => { let type; let dir; let filter; - if (typeof input === 'string' || Array.isArray(input)) { + + if (typeof input === 'string') { + const obj = Util.strToObj(input); + if (obj) { + type = obj.type; + dir = obj.dir; + filter = obj.filter; + } else { + dir = input; + } + } else if (Array.isArray(input)) { dir = input; - filter = () => true; } else { type = input.type; dir = input.dir; diff --git a/lib/utils/util.js b/lib/utils/util.js index 8aa4679a..93e23ec8 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -60,7 +60,7 @@ const Util = { return str; }, - strToObjPatterns: (str) => { + strToObj: (str) => { if (typeof str === 'string') { str = str.trim(); if (str.startsWith('{') && str.endsWith('}')) { diff --git a/lib/v8/v8.js b/lib/v8/v8.js index b085b1a6..07623b82 100644 --- a/lib/v8/v8.js +++ b/lib/v8/v8.js @@ -35,7 +35,7 @@ const getEntryFilter = (options) => { // string to multiple patterns "{...}" // mcr npx mocha --entryFilter {'**/node_modules/**':false,'**/src/*.js':true} // mcr npx mocha --entryFilter "{'**/node_modules/**': false, '**/src/*.js': true}" - const obj = Util.strToObjPatterns(input); + const obj = Util.strToObj(input); if (obj) { input = obj; } else {