import { CommandModule } from 'yargs'; import { Codegen } from './codegen'; import { lint } from './lint'; import { MessageCodegenOptions } from './message-codegen-options'; export const msgCodegen: CommandModule = { command: 'msg-codegen', describe: 'Generates code from AsyncAPI document.', builder: (yargs) => yargs .option('inputDir', { alias: 'i', describe: 'Path to input directory - AsyncAPI document root.', type: 'string', demandOption: true, }) .option('filePattern', { alias: 'p', describe: 'Regular expression that matches suitable input files.', type: 'string', default: '^.*(-asyncapi).(json|yaml|yml)$', }) .option('outputDir', { alias: 'o', describe: 'Path to output directory - output root.', type: 'string', default: 'src/generated', }) .option('lint', { describe: 'Run the Spectral linter on message schemas.', type: 'boolean', default: false, }) .option('rulesetPath', { alias: 'r', describe: 'Path to a Spectral ruleset file for linting.', type: 'string', }), handler: async (argv) => { if (argv.lint) { await lint(argv); } else { const codegen = new Codegen(argv); await codegen.run(); } console.log('done.'); }, };