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: add better reusability for the CLI #2010

Merged
merged 3 commits into from
May 21, 2024
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
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')}`);
}
Loading