-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new command to disable analytics
- Loading branch information
Showing
2 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Flags } from '@oclif/core'; | ||
import { readFileSync, writeFile } from 'fs-extra'; | ||
import { join, resolve } from 'path'; | ||
import Command from '../../base'; | ||
|
||
export default class Analytics extends Command { | ||
static description = 'Enable or disable analytics for metrics collection'; | ||
static flags = { | ||
help: Flags.help({ char: 'h' }), | ||
disable: Flags.boolean({ char: 'd', description: 'disable analytics', default: false }) | ||
}; | ||
|
||
async run() { | ||
try { | ||
const { flags } = await this.parse(Analytics); | ||
const isDisabled = flags.disable; | ||
const analyticsConfigFile = join(process.cwd(), '.asyncapi-analytics'); | ||
const analyticsConfigFileContent = JSON.parse(readFileSync(resolve(process.cwd(), '.asyncapi-analytics'), 'utf-8')); | ||
|
||
if (isDisabled) { | ||
analyticsConfigFileContent.analyticsEnabled = 'false'; | ||
await writeFile(analyticsConfigFile, JSON.stringify(analyticsConfigFileContent), {encoding: 'utf8'}); | ||
this.log('Analytics disabled.'); | ||
} else { | ||
analyticsConfigFileContent.analyticsEnabled = 'true'; | ||
await writeFile(analyticsConfigFile, JSON.stringify(analyticsConfigFileContent), {encoding: 'utf8'}); | ||
this.log('Analytics enabled.'); | ||
} | ||
} catch (e: any) { | ||
this.error(e as Error); | ||
} | ||
} | ||
} |