Skip to content

Commit

Permalink
Update convert command
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-rr authored and smoya committed Nov 22, 2023
1 parent 9952df2 commit 07c7866
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/commands/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ValidationError } from '../errors/validation-error';
import { load } from '../models/SpecificationFile';
import { SpecificationFileNotFound } from '../errors/specification-file';
import { convert } from '@asyncapi/converter';
import { MetadataFromDocument } from '@smoya/asyncapi-adoption-metrics';
import { Parser } from '@asyncapi/parser';

import type { ConvertVersion } from '@asyncapi/converter';

Expand All @@ -27,6 +29,8 @@ export default class Convert extends Command {
{ name: 'spec-file', description: 'spec path, url, or context-name', required: false },
];

parser = new Parser();

async run() {
const { args, flags } = await this.parse(Convert);
const filePath = args['spec-file'];
Expand Down Expand Up @@ -69,5 +73,23 @@ export default class Convert extends Command {
this.error(err as Error);
}
}

try {
// Metrics recording.
const {document} = await this.parser.parse(specFile.text());
if (document !== undefined && convertedFileFormatted) {
const metadata = MetadataFromDocument(document);
metadata['success'] = true;
metadata['from_version'] = metadata['_asyncapi_version'];
metadata['to_version'] = flags['target-version'];
console.log(metadata);
await this.recorder.recordActionExecution('convert', metadata);
await this.recorder.flush();
}
} catch (e: any) {
if (e instanceof Error) {
this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`);
}
}
}
}

0 comments on commit 07c7866

Please sign in to comment.