Skip to content

Commit

Permalink
feat(cli): expose apidoc option, silent (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera authored Jan 29, 2023
1 parent fdffaf2 commit c7a71bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ or Yarn
Options:
-d, --docs Output directory used to compile apidocs [default: "./.docs"]
-p, --port Set mock port [default: 8000]
-s, --silent Silence apiDoc's output warnings, errors
[boolean] [default: true]
-w, --watch Watch single, or multiple directories
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
11 changes: 9 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const packageJson = require('../package');
const { logger } = require('../src/logger/configLogger');
const { apiDocMock } = require('../src');

const { port, watch, docs } = yargs
const { port, silent, watch, docs } = yargs
.usage('Create a mock server from apiDoc comments.\n\nUsage: mock [options]')
.help('help')
.alias('h', 'help')
Expand All @@ -24,6 +24,12 @@ const { port, watch, docs } = yargs
describe: 'Set mock port',
requiresArg: true
})
.option('s', {
alias: 'silent',
default: true,
describe: "Silence apiDoc's output warnings, errors",
type: 'boolean'
})
.option('w', {
alias: 'watch',
describe: 'Watch single, or multiple directories',
Expand All @@ -34,7 +40,8 @@ const start = () =>
apiDocMock({
port: (/^\d+$/g.test(port) && port) || undefined,
dataPath: watch,
docsPath: docs
docsPath: docs,
silent
});

if (process.env.NODE_ENV === 'test') {
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const cache = { app: null, httpTerminator: null };
*
* @param {(string|string[])} dataPath
* @param {string} docsPath
* @param {boolean} silent
* @returns {{}|*}
*/
const setupDocs = (dataPath = '', docsPath = '') => {
const setupDocs = (dataPath = '', docsPath = '', silent) => {
const cwd = process.cwd();
const dest = (docsPath && path.join(cwd, docsPath)) || null;

Expand All @@ -33,7 +34,7 @@ const setupDocs = (dataPath = '', docsPath = '') => {
apimock: path.join(__dirname, './docs/configDocs.js')
},
dryRun: process.env.NODE_ENV === 'test',
silent: process.env.NODE_ENV === 'test'
silent: process.env.NODE_ENV === 'test' || silent
};

const apiJson = buildDocs({ apiDocsConfig });
Expand Down Expand Up @@ -75,10 +76,11 @@ const setupResponse = (apiJson = [], port) => {
* @param {number} params.port
* @param {(string|string[])} params.dataPath
* @param {string} params.docsPath
* @param {boolean} params.silent
* @returns {*}
*/
const apiDocMock = async ({ port = 8000, dataPath, docsPath = '.docs' } = {}) => {
const apiJson = setupDocs(dataPath, docsPath);
const apiDocMock = async ({ port = 8000, dataPath, docsPath = '.docs', silent } = {}) => {
const apiJson = setupDocs(dataPath, docsPath, silent);
let httpTerminator = null;

if (apiJson) {
Expand Down

0 comments on commit c7a71bc

Please sign in to comment.