-
-
Notifications
You must be signed in to change notification settings - Fork 164
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 the flag for disabling optimizations #1447
Changes from 2 commits
de2dd43
57df499
3558b42
f975095
1d073f7
a0e2788
bf3f5f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,10 @@ | |
MOVE_ALL_TO_COMPONENTS='move-all-to-components', | ||
} | ||
|
||
export enum DisableOptimizations { | ||
SCHEMA='schema' | ||
} | ||
|
||
export enum Outputs { | ||
TERMINAL='terminal', | ||
NEW_FILE='new-file', | ||
|
@@ -27,13 +31,15 @@ | |
static description = 'optimize asyncapi specification file'; | ||
isInteractive = false; | ||
selectedOptimizations?: Optimizations[]; | ||
disableOptimizations?: DisableOptimizations[]; | ||
outputMethod?: Outputs; | ||
|
||
static examples = [ | ||
'asyncapi optimize ./asyncapi.yaml', | ||
'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 @@ | |
} | ||
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 @@ | |
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); | ||
|
||
|
@@ -152,6 +163,7 @@ | |
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) { | ||
|
@@ -178,6 +190,11 @@ | |
this.showOptimizations(report.reuseComponents); | ||
choices.push({name: 'reuse components', value: Optimizations.REUSE_COMPONENTS}); | ||
} | ||
if (canIgnoreSchema) { | ||
this.log("Do not ignore schema for the components"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strings must use single quote. |
||
choices.push({name: 'Do not ignore schema', value: DisableOptimizations.SCHEMA}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest we use the same option as flag. I mean the name should be |
||
} | ||
|
||
const optimizationRes = await inquirer.prompt([{ | ||
name: 'optimization', | ||
message: 'select the type of optimization that you want to apply:', | ||
|
@@ -186,6 +203,10 @@ | |
choices | ||
}]); | ||
|
||
if (optimizationRes.optimization.includes('schema')) { | ||
this.disableOptimizations = this.disableOptimizations?.filter(opt => opt !== DisableOptimizations.SCHEMA); | ||
} | ||
|
||
this.selectedOptimizations = optimizationRes.optimization; | ||
|
||
const outputRes = await inquirer.prompt([{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this. we always show this option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, we allow the user to ignore the schema halfway through even if they didn't put the flag initially and vice versa?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included these changes in the last commit.