diff --git a/src/base.ts b/src/base.ts index 94aee8ffe15..ccca24b00a1 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,7 @@ 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'); if (!existsSync(analyticsConfigFile)) { await writeFile(analyticsConfigFile, JSON.stringify({ analyticsEnabled: 'true', infoMessageShown: 'false', userID: uuidv4()}), { encoding: 'utf8' }); @@ -109,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' }); } 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..80471fbb78b 100644 --- a/test/integration/config/analytics.test.ts +++ b/test/integration/config/analytics.test.ts @@ -1,11 +1,6 @@ import { expect, test } from '@oclif/test'; -import { fileCleanup } from '../../helpers'; describe('config:analytics', () => { - afterEach(() => { - fileCleanup('.asyncapi-analytics'); - }); - describe('with disable flag', () => { test .stderr()