From 3d9be1383cb04843e908247fcc4600713646f57c Mon Sep 17 00:00:00 2001 From: SahilDahekar Date: Mon, 23 Dec 2024 22:17:22 +0530 Subject: [PATCH 1/2] Resolved the spinner loading even after error in console --- package-lock.json | 4 ++-- src/commands/generate/models.ts | 36 +++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 70f3758136c..d76edc616b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@asyncapi/cli", - "version": "2.13.0", + "version": "2.14.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@asyncapi/cli", - "version": "2.13.0", + "version": "2.14.0", "license": "Apache-2.0", "dependencies": { "@asyncapi/avro-schema-parser": "^3.0.23", diff --git a/src/commands/generate/models.ts b/src/commands/generate/models.ts index 1303d442c95..98f3308a5d0 100644 --- a/src/commands/generate/models.ts +++ b/src/commands/generate/models.ts @@ -56,19 +56,29 @@ export default class Models extends Command { const s = spinner(); s.start('Generating models...'); - const generatedModels = await generateModels({...flags, output}, document, logger, language as Languages); - if (output !== 'stdout') { - const generatedModelStrings = generatedModels.map((model) => { return model.modelName; }); - s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`)); - return; - } - const generatedModelStrings = generatedModels.map((model) => { - return ` -## Model name: ${model.modelName} -${model.result} - `; - }); - s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`)); + try { + const generatedModels = await generateModels({...flags, output}, document, logger, language as Languages); + if (output !== 'stdout') { + const generatedModelStrings = generatedModels.map((model) => { return model.modelName; }); + s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`)); + return; + } + const generatedModelStrings = generatedModels.map((model) => { + return ` + ## Model name: ${model.modelName} + ${model.result} + `; + }); + s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`)); + } catch (error) { + s.stop(green("Failed to generate models")); + + if (error instanceof Error) { + this.error(error.message); + } else { + this.error('An unknown error occurred during model generation.'); + } + } } private async parseArgs(args: Record, output?: string) { From fbd0f6a86a19e54a1ac5602d765552668e68793a Mon Sep 17 00:00:00 2001 From: SahilDahekar Date: Mon, 23 Dec 2024 22:24:14 +0530 Subject: [PATCH 2/2] Fixed lint error --- src/commands/generate/models.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/generate/models.ts b/src/commands/generate/models.ts index 98f3308a5d0..5c7a04f82a2 100644 --- a/src/commands/generate/models.ts +++ b/src/commands/generate/models.ts @@ -71,7 +71,7 @@ export default class Models extends Command { }); s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`)); } catch (error) { - s.stop(green("Failed to generate models")); + s.stop(green('Failed to generate models')); if (error instanceof Error) { this.error(error.message);