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: change .asyncapi-analytics file's directory #1370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -86,7 +87,7 @@ export default abstract class extends Command {

async recorderFromEnv(prefix: string): Promise<Recorder> {
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' });
Expand All @@ -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' });
}
Expand Down
5 changes: 3 additions & 2 deletions src/commands/config/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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' }));
Expand All @@ -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.`);
Expand Down
5 changes: 0 additions & 5 deletions test/integration/config/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Loading