import type { CommandModule } from 'yargs'; import { Codegen } from './codegen.js'; import { lint } from './lint.js'; import type { MessageCodegenOptions } from './message-codegen-options.js'; 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', }) .option('importSpecifierExtension', { alias: 'e', describe: 'Extension appended to relative import specifiers in generated barrel files (e.g. ".js" for ESM-compatible output). Default empty string preserves existing CJS behaviour.', type: 'string', default: '', }), handler: async (argv) => { if (argv.lint) { await lint(argv); } else { const codegen = new Codegen(argv); await codegen.run(); } console.log('done.'); }, };