From 4627ea5cc30b1b40529ed2b70c429b50fa57c74a Mon Sep 17 00:00:00 2001 From: Korada Vishal <116670999+Vishalk91-4@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:29:08 +0530 Subject: [PATCH] chore: added ui/ux improvements in optimize commands (#1526) * Added UI Changes to Optimize Command * fix: failing tests Signed-off-by: Vishal K --------- Signed-off-by: Vishal K Co-authored-by: souvik --- .asyncapi-cli | 1 + src/commands/optimize.ts | 11 ++++++----- src/core/errors/validation-error.ts | 4 ++-- test/integration/optimize.test.ts | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .asyncapi-cli diff --git a/.asyncapi-cli b/.asyncapi-cli new file mode 100644 index 00000000000..169c09a3f6b --- /dev/null +++ b/.asyncapi-cli @@ -0,0 +1 @@ +{"current":"eight-context","store":{"seven-context":".","eight-context":"."}} \ No newline at end of file diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index cbd2702a3ce..4607ab3ec2c 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -85,7 +85,7 @@ export default class Optimize extends Command { this.metricsMetadata.optimized = false; if (!(report.moveDuplicatesToComponents?.length || report.removeComponents?.length || report.reuseComponents?.length)) { - this.log(`No optimization has been applied since ${this.specFile.getFilePath() ?? this.specFile.getFileURL()} looks optimized!`); + this.log(`🎉 Great news! Your file at ${this.specFile.getFilePath() ?? this.specFile.getFileURL()} is already optimized.`); return; } @@ -120,21 +120,22 @@ export default class Optimize extends Command { switch (this.outputMethod) { case Outputs.TERMINAL: + this.log('📄 Here is your optimized AsyncAPI document:\n'); this.log(optimizedDocument); break; case Outputs.NEW_FILE: await writeFile(newPath, optimizedDocument, { encoding: 'utf8' }); - this.log(`Created file ${newPath}...`); + this.log(`✅ Success! Your optimized file has been created at ${chalk.blue({newPath})}.`); break; case Outputs.OVERWRITE: await writeFile(specPath ?? 'asyncapi.yaml', optimizedDocument, { encoding: 'utf8' }); - this.log(`Updated file ${specPath}...`); + this.log(`✅ Success! Your original file at ${specPath} has been updated.`); break; } } catch (error) { throw new ValidationError({ type: 'parser-error', - err: error + err: error, }); } } @@ -219,7 +220,7 @@ export default class Optimize extends Command { message: 'where do you want to save the result:', type: 'list', default: 'log to terminal', - choices: [{name: 'log to terminal',value: Outputs.TERMINAL}, {name: 'create new file', value: Outputs.NEW_FILE}, {name: 'update original', value: Outputs.OVERWRITE}] + choices: [{name: 'log to terminal',value: Outputs.TERMINAL}, {name: 'create new file', value: Outputs.NEW_FILE}, {name: 'update original file', value: Outputs.OVERWRITE}] }]); this.outputMethod = outputRes.output; } diff --git a/src/core/errors/validation-error.ts b/src/core/errors/validation-error.ts index 7327734270f..c8386082f59 100644 --- a/src/core/errors/validation-error.ts +++ b/src/core/errors/validation-error.ts @@ -37,8 +37,8 @@ export class ValidationError extends Error { const errorHasTitle = !!e.title; const errorHasLocation = !!e.location; /* - * All the conditions below are needed since validationErrors (from ParserError) come from Parser JS library, - * so we cannot assure that all the fields or properties are always provided in the error. There might be cases + * All the conditions below are needed since validationErrors (from ParserError) come from Parser JS library, + * so we cannot assure that all the fields or properties are always provided in the error. There might be cases * that even title is not provided. */ if (errorHasTitle && errorHasLocation) { diff --git a/test/integration/optimize.test.ts b/test/integration/optimize.test.ts index e0adbdec117..1f921e11669 100644 --- a/test/integration/optimize.test.ts +++ b/test/integration/optimize.test.ts @@ -34,7 +34,7 @@ describe('optimize', () => { .stdout() .command(['optimize', optimizedFilePath]) .it('works when file path is passed', (ctx, done) => { - expect(ctx.stdout).to.contain(`No optimization has been applied since ${optimizedFilePath} looks optimized!`); + expect(ctx.stdout).to.contain(`🎉 Great news! Your file at ${optimizedFilePath} is already optimized.`); expect(ctx.stderr).to.equal(''); done(); }); @@ -54,7 +54,7 @@ describe('optimize', () => { .stdout() .command(['optimize', 'http://localhost:8080/dummySpecWithoutSecurity.yml']) .it('works when url is passed', (ctx, done) => { - expect(ctx.stdout).to.contain('No optimization has been applied since http://localhost:8080/dummySpecWithoutSecurity.yml looks optimized!'); + expect(ctx.stdout).to.contain('🎉 Great news! Your file at http://localhost:8080/dummySpecWithoutSecurity.yml is already optimized.'); expect(ctx.stderr).to.equal(''); done(); }); @@ -75,7 +75,7 @@ describe('optimize', () => { .stdout() .command(['optimize']) .it('converts from current context', (ctx, done) => { - expect(ctx.stdout).to.contain(`No optimization has been applied since ${path.resolve(__dirname, '../fixtures/specification.yml')} looks optimized!`); + expect(ctx.stdout).to.contain(`🎉 Great news! Your file at ${path.resolve(__dirname, '../fixtures/specification.yml')} is already optimized.`); expect(ctx.stderr).to.equal(''); done(); });