Skip to content

Commit

Permalink
added --all option for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed May 9, 2024
1 parent d9f57ec commit d99667c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path> custom config file path
-l, --logging <logging> off, error, info, debug
-n, --name <name> report name for title
-r, --reports <name[,name]> coverage reports to use
-o, --outputDir <dir> output dir for reports
-i, --inputDir <dir> input dir for merging raw files
--entryFilter <pattern> entry url filter
--sourceFilter <pattern> source path filter
--outputFile <path> output file for v8 report
--inline inline html for v8 report
--assetsPath <path> assets path if not inline
--lcov generate lcov.info file
--import <module> preload module at startup
--require <module> 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
Expand Down
27 changes: 1 addition & 26 deletions README.zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path> custom config file path
-l, --logging <logging> off, error, info, debug
-n, --name <name> report name for title
-r, --reports <name[,name]> coverage reports to use
-o, --outputDir <dir> output dir for reports
-i, --inputDir <dir> input dir for merging raw files
--entryFilter <pattern> entry url filter
--sourceFilter <pattern> source path filter
--outputFile <path> output file for v8 report
--inline inline html for v8 report
--assetsPath <path> assets path if not inline
--lcov generate lcov.info file
--import <module> preload module at startup
--require <module> preload module at startup
-h, --help display help for command
```
直接运行 `mcr` 或 `mcr --help` 查看所有CLI的参数
- 使用 `--` 可以隔离子程序参数,以免两种参数混淆
```sh
Expand Down
2 changes: 2 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ program
.option('-o, --outputDir <dir>', 'output dir for reports')
.option('-i, --inputDir <dir>', 'input dir for merging raw files')

.option('-a, --all <dir>', 'include all files from dir')

.option('--entryFilter <pattern>', 'entry url filter')
.option('--sourceFilter <pattern>', 'source path filter')

Expand Down
2 changes: 1 addition & 1 deletion lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Util = {
return str;
},

strToObjPatterns: (str) => {
strToObj: (str) => {
if (typeof str === 'string') {
str = str.trim();
if (str.startsWith('{') && str.endsWith('}')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/v8/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d99667c

Please sign in to comment.