Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): expose apidoc option, silent #211

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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