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

fix: solve optimize command issue when sending data to New Relic #13

Merged
15 changes: 11 additions & 4 deletions src/commands/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ export default class Optimize extends Command {
this.optimizations = flags.optimization as Optimizations[];
this.outputMethod = flags.output as Outputs;

if (report.moveToComponents?.length || report.removeComponents?.length || report.reuseComponents?.length) {
this.metricsMetadata.optimized = true;
await this.collectMetricsData(report);
} else {
if (!(report.moveToComponents?.length || report.removeComponents?.length || report.reuseComponents?.length)) {
this.metricsMetadata.optimized = false;
this.log(`No optimization has been applied since ${this.specFile.getFilePath() ?? this.specFile.getFileURL()} looks optimized!`);
return;
Expand All @@ -105,6 +102,9 @@ export default class Optimize extends Command {
reuseComponents: this.optimizations.includes(Optimizations.REUSE_COMPONENTS)
}, output: Output.YAML});

this.metricsMetadata.optimized = true;
await this.collectMetricsData(report);

const specPath = this.specFile.getFilePath();
let newPath = '';

Expand Down Expand Up @@ -137,14 +137,20 @@ export default class Optimize extends Command {
if (!elements) {
return;
}

this.metricsMetadata.optimized = true;
peter-rr marked this conversation as resolved.
Show resolved Hide resolved

for (let i = 0; i < elements.length; i++) {
const element = elements[+i];
if (element.action==='move') {
this.log(`${chalk.green('move')} ${element.path} to ${element.target} and reference it.`);
this.metricsMetadata.optimization_moveToComponents = true;
peter-rr marked this conversation as resolved.
Show resolved Hide resolved
} else if (element.action==='reuse') {
this.log(`${chalk.green('reuse')} ${element.target} in ${element.path}.`);
this.metricsMetadata.optimization_reuseComponents = true;
} else if (element.action === 'remove') {
this.log(`${chalk.red('remove')} ${element.path}.`);
this.metricsMetadata.optimization_removeComponents = true;
}
}

Expand Down Expand Up @@ -196,6 +202,7 @@ export default class Optimize extends Command {

private async collectMetricsData(report: Report) {
peter-rr marked this conversation as resolved.
Show resolved Hide resolved
try {
// Metrics collection when not using an interactive terminal
if (report.moveToComponents?.length) {
this.metricsMetadata.optimization_moveToComponents = true;
}
Expand Down
Loading