From f70e97b8e1ad618900f6f08618aecc72041873ec Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Wed, 17 Apr 2024 13:03:11 +0200 Subject: [PATCH 1/3] Change analytics config file directory --- src/base.ts | 4 +++- src/commands/config/analytics.ts | 5 +++-- test/integration/config/analytics.test.ts | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/base.ts b/src/base.ts index 94aee8ffe15..d6b0be37028 100644 --- a/src/base.ts +++ b/src/base.ts @@ -6,6 +6,7 @@ import { join, resolve } from 'path'; import { existsSync } from 'fs-extra'; import { promises as fPromises } from 'fs'; import { v4 as uuidv4 } from 'uuid'; +import { homedir } from 'os'; const { readFile, writeFile } = fPromises; @@ -86,7 +87,8 @@ export default abstract class extends Command { async recorderFromEnv(prefix: string): Promise { let sink: Sink = new DiscardSink(); - const analyticsConfigFile = join(process.cwd(), '.asyncapi-analytics'); + const analyticsConfigFile = join(homedir(), '.asyncapi-analytics'); + // console.log(analyticsConfigFile); if (!existsSync(analyticsConfigFile)) { await writeFile(analyticsConfigFile, JSON.stringify({ analyticsEnabled: 'true', infoMessageShown: 'false', userID: uuidv4()}), { encoding: 'utf8' }); diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index 0e1970406c3..e9c1fdaf224 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -2,6 +2,7 @@ import { Flags } from '@oclif/core'; import { join, resolve } from 'path'; import Command from '../../base'; import { promises as fPromises } from 'fs'; +import { homedir } from 'os'; const { readFile, writeFile } = fPromises; @@ -15,7 +16,7 @@ export default class Analytics extends Command { async run() { const { flags } = await this.parse(Analytics); - const analyticsConfigFile = join(process.cwd(), '.asyncapi-analytics'); + const analyticsConfigFile = join(homedir(), '.asyncapi-analytics'); try { const analyticsConfigFileContent = JSON.parse(await readFile(resolve(analyticsConfigFile), { encoding: 'utf8' })); @@ -34,7 +35,7 @@ export default class Analytics extends Command { } catch (e: any) { switch (e.code) { case 'ENOENT': - this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in your current working directory ("${process.cwd()}") but the file could not be found.`); + this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in your user's home directory ("${homedir()}") but the file could not be found.`); break; case 'EEXIST': this.error(`Unable to update the analytics configuration file. We tried to update your ".asyncapi-analytics" file in the path "${analyticsConfigFile}" but the file does not exist.`); diff --git a/test/integration/config/analytics.test.ts b/test/integration/config/analytics.test.ts index 8f5ae75183d..1508a75a913 100644 --- a/test/integration/config/analytics.test.ts +++ b/test/integration/config/analytics.test.ts @@ -1,9 +1,11 @@ import { expect, test } from '@oclif/test'; import { fileCleanup } from '../../helpers'; +import { join } from 'path'; +import { homedir } from 'os'; describe('config:analytics', () => { afterEach(() => { - fileCleanup('.asyncapi-analytics'); + fileCleanup(join(homedir(), '.asyncapi-analytics')); }); describe('with disable flag', () => { From ed1bf3325ea9f2084f493fde9e13116f96ca80bd Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Wed, 17 Apr 2024 17:27:56 +0200 Subject: [PATCH 2/3] Solve sonarcloud issue --- src/base.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/base.ts b/src/base.ts index d6b0be37028..ccca24b00a1 100644 --- a/src/base.ts +++ b/src/base.ts @@ -88,7 +88,6 @@ export default abstract class extends Command { async recorderFromEnv(prefix: string): Promise { let sink: Sink = new DiscardSink(); const analyticsConfigFile = join(homedir(), '.asyncapi-analytics'); - // console.log(analyticsConfigFile); if (!existsSync(analyticsConfigFile)) { await writeFile(analyticsConfigFile, JSON.stringify({ analyticsEnabled: 'true', infoMessageShown: 'false', userID: uuidv4()}), { encoding: 'utf8' }); @@ -111,7 +110,7 @@ export default abstract class extends Command { sink = new NewRelicSink(process.env.ASYNCAPI_METRICS_NEWRELIC_KEY || 'eu01xx73a8521047150dd9414f6aedd2FFFFNRAL'); if (analyticsConfigFileContent.infoMessageShown === 'false') { - this.log('\nAsyncAPI anonymously tracks command executions to improve the specification and tools, ensuring no sensitive data reaches our servers. It aids in comprehending how AsyncAPI tools are used and adopted, facilitating ongoing improvements to our specifications and tools.\n\nTo disable tracking, please run the following command:\n asyncapi config analytics --disable\n\nOnce disabled, if you want to enable tracking back again then run:\n asyncapi config analytics --enable'); + this.log('\nAsyncAPI anonymously tracks command executions to improve the specification and tools, ensuring no sensitive data reaches our servers. It aids in comprehending how AsyncAPI tools are used and adopted, facilitating ongoing improvements to our specifications and tools.\n\nTo disable tracking, please run the following command:\n asyncapi config analytics --disable\n\nOnce disabled, if you want to enable tracking back again then run:\n asyncapi config analytics --enable\n'); analyticsConfigFileContent.infoMessageShown = 'true'; await writeFile(analyticsConfigFile, JSON.stringify(analyticsConfigFileContent), { encoding: 'utf8' }); } From c20b8f00cfebc362c51f7eb0d32d396874a68ba0 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Wed, 17 Apr 2024 17:31:58 +0200 Subject: [PATCH 3/3] Modify analytics tests --- test/integration/config/analytics.test.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/integration/config/analytics.test.ts b/test/integration/config/analytics.test.ts index 1508a75a913..80471fbb78b 100644 --- a/test/integration/config/analytics.test.ts +++ b/test/integration/config/analytics.test.ts @@ -1,13 +1,6 @@ import { expect, test } from '@oclif/test'; -import { fileCleanup } from '../../helpers'; -import { join } from 'path'; -import { homedir } from 'os'; describe('config:analytics', () => { - afterEach(() => { - fileCleanup(join(homedir(), '.asyncapi-analytics')); - }); - describe('with disable flag', () => { test .stderr()