From 07c7866d108fb3232d1fa70408b1eddcf23f4567 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Mon, 6 Nov 2023 12:50:07 +0100 Subject: [PATCH] Update convert command --- src/commands/convert.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/commands/convert.ts b/src/commands/convert.ts index b404a6df3f6..871bd820903 100644 --- a/src/commands/convert.ts +++ b/src/commands/convert.ts @@ -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'; @@ -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']; @@ -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}`); + } + } } }