import { CommandModule } from 'yargs'; import { CreateMockServerOptions, createMultiProcessPrism, createSingleProcessPrism } from '../util/createServer'; import sharedOptions from './sharedOptions'; import { runPrismAndSetupWatcher } from '../util/runner'; const mockCommand: CommandModule = { describe: 'Start a mock server with the given document file', command: 'mock ', builder: yargs => yargs .positional('document', { description: 'Path to a document file. Can be both a file or a fetchable resource on the web.', type: 'string', }) .options({ ...sharedOptions, dynamic: { alias: 'd', description: 'Dynamically generate examples.', boolean: true, default: false, }, }), handler: parsedArgs => { const { multiprocess, dynamic, port, host, cors, document, errors, verboseLevel } = parsedArgs as unknown as CreateMockServerOptions; const createPrism = multiprocess ? createMultiProcessPrism : createSingleProcessPrism; const options = { cors, dynamic, port, host, document, multiprocess, errors, verboseLevel }; return runPrismAndSetupWatcher(createPrism, options); }, }; export default mockCommand;