Skip to content

Commit

Permalink
add options for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jan 19, 2024
1 parent 34cbff4 commit ce74419
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,19 @@ const initOptions = (cliOptions) => {
const configPath = cliOptions.config;
if (configPath) {
if (fs.existsSync(configPath)) {
const config = require(configPath);
const config = require(path.resolve(configPath));
Object.assign(options, config);
} else {
EC.logRed(`Not found config: ${configPath}`);
}
}

// list with `,`
const reports = cliOptions.reports;
if (reports) {
cliOptions.reports = reports.split(',');
}

Object.keys(cliOptions).forEach((k) => {
if (Util.hasOwn(options, k)) {
options[k] = cliOptions[k];
Expand All @@ -114,6 +120,15 @@ program
.argument('<command>', 'command to execute')
.option('-c, --config <path>')
.option('-o, --outputDir <dir>')
.option('-r, --reports <report-name[,report-name]>')
.option('-n, --name <name>')

.option('--outputFile <outputFile>')
.option('--inline')
.option('--assetsPath <assetsPath>')

.option('--lcov')

.action((command, cliOptions) => {
const options = initOptions(cliOptions);
executeCommand(command, options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
"test-node-koa": "node ./test/test-node-koa.js",
"test-browser": "node ./test/test.js",
"test-cli": "npx mcr \"node ./test/test-node-env.js\" --outputDir=docs/cli",
"test-cli": "npx mcr \"node ./test/test-node-env.js\" -o docs/cli -r v8,console-summary --lcov -c test/cli-options.js",
"test": "npm run test-browser && npm run test-node && npm run test-cli && npm run build-docs",
"dev": "sf d v8",
"open": "node ./scripts/open.js",
Expand Down
11 changes: 11 additions & 0 deletions test/cli-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {

entryFilter: (entry) => {
return entry.url.includes('mock/node');
},

onEnd: () => {
console.log('test cli end');
}

};

0 comments on commit ce74419

Please sign in to comment.