Skip to content

Commit

Permalink
feat: add better reusability for the CLI (#2010)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored May 21, 2024
1 parent faa6bfd commit 0cd15c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
16 changes: 15 additions & 1 deletion modelina-cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export default class Models extends ModelinaCommand {
},
}

await generateModels(flags, document, logger, language as Languages);
const generatedModels = await generateModels(flags, document, logger, language as Languages);

if (flags.output) {
const generatedModelsString = generatedModels.map((model) => { return model.modelName; });
logger.info(`Successfully generated the following models: ${generatedModelsString.join(', ')}`);
} else {
const generatedModelsString = generatedModels.map((model) => {
return `## Model name: ${model.modelName}
${model.result}
`;
});
logger.info(`Successfully generated the following models: ${generatedModelsString.join('\n')}`);
}


}
}
14 changes: 2 additions & 12 deletions modelina-cli/src/helpers/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,13 @@ export async function generateModels(flags: any, document: any, logger: any, lan
const { fileGenerator, fileOptions } = mapper(flags);

if (output) {
const models = await fileGenerator.generateToFiles(
return fileGenerator.generateToFiles(
document,
output,
{ ...fileOptions, });
const generatedModels = models.map((model) => { return model.modelName; });
logger.info(`Successfully generated the following models: ${generatedModels.join(', ')}`);
return;
}

const models = await fileGenerator.generateCompleteModels(
return fileGenerator.generateCompleteModels(
document,
{ ...fileOptions });
const generatedModels = models.map((model) => {
return `
## Model name: ${model.modelName}
${model.result}
`;
});
logger.info(`Successfully generated the following models: ${generatedModels.join('\n')}`);
}

0 comments on commit 0cd15c0

Please sign in to comment.