From de2dd4355d7a5afde7b9192fcef6734d4e81b796 Mon Sep 17 00:00:00 2001 From: helios2003 Date: Mon, 24 Jun 2024 09:25:09 +0530 Subject: [PATCH 1/3] fixes in ignore flag --- src/commands/optimize.ts | 13 ++++++++++++- src/core/flags/optimize.flags.ts | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index d5e81f4e499..76b7045bd53 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -18,6 +18,10 @@ export enum Optimizations { MOVE_ALL_TO_COMPONENTS='move-all-to-components', } +export enum DisableOptimizations { + SCHEMA='schema' +} + export enum Outputs { TERMINAL='terminal', NEW_FILE='new-file', @@ -27,6 +31,7 @@ export default class Optimize extends Command { static description = 'optimize asyncapi specification file'; isInteractive = false; selectedOptimizations?: Optimizations[]; + disableOptimizations?: DisableOptimizations[]; outputMethod?: Outputs; static examples = [ @@ -34,6 +39,7 @@ export default class Optimize extends Command { 'asyncapi optimize ./asyncapi.yaml --no-tty', 'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --optimization=reuse-components --optimization=move-all-to-components --no-tty', 'asyncapi optimize ./asyncapi.yaml --optimization=remove-components --output=terminal --no-tty', + 'asyncapi optimize ./asyncapi.yaml --ignore=schema' ]; static flags = optimizeFlags(); @@ -74,6 +80,7 @@ export default class Optimize extends Command { } this.isInteractive = !flags['no-tty']; this.selectedOptimizations = flags.optimization as Optimizations[]; + this.disableOptimizations = flags.ignore as DisableOptimizations[]; this.outputMethod = flags.output as Outputs; this.metricsMetadata.optimized = false; @@ -93,7 +100,11 @@ export default class Optimize extends Command { moveAllToComponents: this.selectedOptimizations.includes(Optimizations.MOVE_ALL_TO_COMPONENTS), removeComponents: this.selectedOptimizations.includes(Optimizations.REMOVE_COMPONENTS), reuseComponents: this.selectedOptimizations.includes(Optimizations.REUSE_COMPONENTS) - }, output: Output.YAML}); + }, + disableOptimizationFor: { + schema: this.disableOptimizations.includes(DisableOptimizations.SCHEMA) + }, + output: Output.YAML}); this.collectMetricsData(report); diff --git a/src/core/flags/optimize.flags.ts b/src/core/flags/optimize.flags.ts index b9a5aa2c707..8fc1f8cb58f 100644 --- a/src/core/flags/optimize.flags.ts +++ b/src/core/flags/optimize.flags.ts @@ -7,6 +7,10 @@ export enum Optimizations { MOVE_ALL_TO_COMPONENTS='move-all-to-components', } +export enum DisableOptimizations { + SCHEMA='schema', +} + export enum Outputs { TERMINAL='terminal', NEW_FILE='new-file', @@ -17,6 +21,7 @@ export const optimizeFlags = () => { return { help: Flags.help({ char: 'h' }), optimization: Flags.string({char: 'p', default: Object.values(Optimizations), options: Object.values(Optimizations), multiple: true, description: 'select the type of optimizations that you want to apply.'}), + ignore: Flags.string({char: 'i', default: [], options: Object.values(DisableOptimizations), multiple: true, description: 'list of components to be ignored from the optimization process'}), output: Flags.string({char: 'o', default: Outputs.TERMINAL, options: Object.values(Outputs), description: 'select where you want the output.'}), 'no-tty': Flags.boolean({ description: 'do not use an interactive terminal', default: false }), }; From 57df499060a941ced574160b7cd1911a4dd133e4 Mon Sep 17 00:00:00 2001 From: helios2003 Date: Fri, 5 Jul 2024 00:59:20 +0530 Subject: [PATCH 2/3] add flexibility to the ignore flag --- src/commands/optimize.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index 76b7045bd53..72bd0ab8034 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -163,6 +163,7 @@ export default class Optimize extends Command { const canMoveAll = report.moveAllToComponents?.length; const canRemove = report.removeComponents?.length; const canReuse = report.reuseComponents?.length; + const canIgnoreSchema = this.disableOptimizations?.includes(DisableOptimizations.SCHEMA); const choices = []; if (canMoveAll) { @@ -189,6 +190,11 @@ export default class Optimize extends Command { this.showOptimizations(report.reuseComponents); choices.push({name: 'reuse components', value: Optimizations.REUSE_COMPONENTS}); } + if (canIgnoreSchema) { + this.log("Do not ignore schema for the components"); + choices.push({name: 'Do not ignore schema', value: DisableOptimizations.SCHEMA}); + } + const optimizationRes = await inquirer.prompt([{ name: 'optimization', message: 'select the type of optimization that you want to apply:', @@ -197,6 +203,10 @@ export default class Optimize extends Command { choices }]); + if (optimizationRes.optimization.includes('schema')) { + this.disableOptimizations = this.disableOptimizations?.filter(opt => opt !== DisableOptimizations.SCHEMA); + } + this.selectedOptimizations = optimizationRes.optimization; const outputRes = await inquirer.prompt([{ From 3558b4257ffca68795b57f335f534b4c0d86b16d Mon Sep 17 00:00:00 2001 From: helios2003 Date: Tue, 9 Jul 2024 13:57:14 +0530 Subject: [PATCH 3/3] give option for schema everytime --- src/commands/optimize.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index 72bd0ab8034..cbd2702a3ce 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -163,7 +163,6 @@ export default class Optimize extends Command { const canMoveAll = report.moveAllToComponents?.length; const canRemove = report.removeComponents?.length; const canReuse = report.reuseComponents?.length; - const canIgnoreSchema = this.disableOptimizations?.includes(DisableOptimizations.SCHEMA); const choices = []; if (canMoveAll) { @@ -190,9 +189,11 @@ export default class Optimize extends Command { this.showOptimizations(report.reuseComponents); choices.push({name: 'reuse components', value: Optimizations.REUSE_COMPONENTS}); } - if (canIgnoreSchema) { - this.log("Do not ignore schema for the components"); + + if (this.disableOptimizations?.includes(DisableOptimizations.SCHEMA)) { choices.push({name: 'Do not ignore schema', value: DisableOptimizations.SCHEMA}); + } else { + choices.push({name: 'Ignore schema', value: DisableOptimizations.SCHEMA}); } const optimizationRes = await inquirer.prompt([{ @@ -204,7 +205,11 @@ export default class Optimize extends Command { }]); if (optimizationRes.optimization.includes('schema')) { - this.disableOptimizations = this.disableOptimizations?.filter(opt => opt !== DisableOptimizations.SCHEMA); + if (this.disableOptimizations?.includes(DisableOptimizations.SCHEMA)) { + this.disableOptimizations = this.disableOptimizations?.filter(opt => opt !== DisableOptimizations.SCHEMA); + } else { + this.disableOptimizations = [...(this.disableOptimizations || []), DisableOptimizations.SCHEMA]; + } } this.selectedOptimizations = optimizationRes.optimization;