From 7bc7fc7e7d426208e06b9165199f0d145ef35a07 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 30 Mar 2021 11:50:49 +0100 Subject: [PATCH] lint :sparkles: --- packages/cli/src/analytics/Client.js | 15 +++--- packages/cli/src/analytics/index.js | 57 ++++++++++---------- packages/cli/src/constants.js | 5 +- packages/cli/src/hosting/index.js | 4 +- packages/cli/src/structures/ConfigManager.js | 15 ++++-- 5 files changed, 51 insertions(+), 45 deletions(-) diff --git a/packages/cli/src/analytics/Client.js b/packages/cli/src/analytics/Client.js index 83eca791ad..d97fb1abfa 100644 --- a/packages/cli/src/analytics/Client.js +++ b/packages/cli/src/analytics/Client.js @@ -1,13 +1,16 @@ const PostHog = require("posthog-node") -const path = require("path") -const fs = require("fs") -const os = require("os") -const { BUDIBASE_POSTHOG_URL, BUDIBASE_POSTHOG_TOKEN, AnalyticsEvents } = require("../constants") +const { + BUDIBASE_POSTHOG_URL, + BUDIBASE_POSTHOG_TOKEN, + AnalyticsEvents, +} = require("../constants") const ConfigManager = require("../structures/ConfigManager") class AnalyticsClient { constructor() { - this.client = new PostHog(BUDIBASE_POSTHOG_TOKEN, { host: BUDIBASE_POSTHOG_URL }) + this.client = new PostHog(BUDIBASE_POSTHOG_TOKEN, { + host: BUDIBASE_POSTHOG_URL, + }) this.configManager = new ConfigManager() } @@ -32,4 +35,4 @@ class AnalyticsClient { } } -module.exports = AnalyticsClient \ No newline at end of file +module.exports = AnalyticsClient diff --git a/packages/cli/src/analytics/index.js b/packages/cli/src/analytics/index.js index d11e8d6a3a..3d8ea8c5a7 100644 --- a/packages/cli/src/analytics/index.js +++ b/packages/cli/src/analytics/index.js @@ -1,15 +1,6 @@ const Command = require("../structures/Command") -const { CommandWords, InitTypes, BUDIBASE_POSTHOG_URL } = require("../constants") -const { lookpath } = require("lookpath") -const { - success, - error, - info, - parseEnv, -} = require("../utils") -const { confirmation } = require("../questions") -const fs = require("fs") -const axios = require("axios") +const { CommandWords } = require("../constants") +const { success, error } = require("../utils") const AnalyticsClient = require("./Client") const client = new AnalyticsClient() @@ -18,9 +9,18 @@ async function optOut() { try { // opt them out client.disable() - console.log(success("Successfully opted out of budibase analytics. You can opt in at any time by running 'budi analytics opt-in'")) - } catch (err) { - console.log(error("Error opting out of budibase analytics. Please try again later.", err)) + console.log( + success( + "Successfully opted out of budibase analytics. You can opt in at any time by running 'budi analytics opt-in'" + ) + ) + } catch (err) { + console.log( + error( + "Error opting out of budibase analytics. Please try again later.", + err + ) + ) } } @@ -28,9 +28,15 @@ async function optIn() { try { // opt them in client.enable() - console.log(success("Successfully opted in to budibase analytics. Thank you for helping us make budibase better!")) - } catch (err) { - console.log(error("Error opting in to budibase analytics. Please try again later.")) + console.log( + success( + "Successfully opted in to budibase analytics. Thank you for helping us make budibase better!" + ) + ) + } catch (err) { + console.log( + error("Error opting in to budibase analytics. Please try again later.") + ) } } @@ -38,23 +44,16 @@ async function status() { try { console.log(success(`Budibase analytics ${client.status()}`)) } catch (err) { - console.log(error("Error fetching analytics status. Please try again later.")) + console.log( + error("Error fetching analytics status. Please try again later.") + ) } } - const command = new Command(`${CommandWords.ANALYTICS}`) .addHelp("Control the analytics you send to budibase.") - .addSubOption( - "--optin", - "Opt in to sending analytics to budibase", - optIn - ) - .addSubOption( - "--optout", - "Opt out of sending analytics to budibase.", - optOut - ) + .addSubOption("--optin", "Opt in to sending analytics to budibase", optIn) + .addSubOption("--optout", "Opt out of sending analytics to budibase.", optOut) .addSubOption( "--status", "Check whether you are currently opted in to budibase analytics.", diff --git a/packages/cli/src/constants.js b/packages/cli/src/constants.js index 1bc668cc8e..a5d24514b8 100644 --- a/packages/cli/src/constants.js +++ b/packages/cli/src/constants.js @@ -12,9 +12,8 @@ exports.InitTypes = { exports.AnalyticsEvents = { OptOut: "analytics_opt_out", OptIn: "analytics_opt_in", - SelfHostInit: "hosting_init" + SelfHostInit: "hosting_init", } - exports.BUDIBASE_POSTHOG_URL = "https://posthog.budi.live" -exports.BUDIBASE_POSTHOG_TOKEN = process.env.BUDIBASE_POSTHOG_TOKEN \ No newline at end of file +exports.BUDIBASE_POSTHOG_TOKEN = process.env.BUDIBASE_POSTHOG_TOKEN diff --git a/packages/cli/src/hosting/index.js b/packages/cli/src/hosting/index.js index 42aab93ac3..60d9f13e80 100644 --- a/packages/cli/src/hosting/index.js +++ b/packages/cli/src/hosting/index.js @@ -77,8 +77,8 @@ async function init(type) { distinctId: "cli", event: AnalyticsEvents.SelfHostInit, properties: { - type - } + type, + }, }) await downloadFiles() const config = isQuick ? makeEnv.QUICK_CONFIG : {} diff --git a/packages/cli/src/structures/ConfigManager.js b/packages/cli/src/structures/ConfigManager.js index 1fc1f43cfc..04b7875b57 100644 --- a/packages/cli/src/structures/ConfigManager.js +++ b/packages/cli/src/structures/ConfigManager.js @@ -6,16 +6,21 @@ const { error } = require("../utils") class ConfigManager { constructor() { this.path = path.join(os.homedir(), ".budibase.json") - if (!fs.existsSync(this.path)) { + if (!fs.existsSync(this.path)) { fs.writeFileSync(this.path, "{}") - } + } } get config() { try { return JSON.parse(fs.readFileSync(this.path, "utf8")) } catch (err) { - console.log(error(("Error parsing configuration file. Please check your .budibase.json is valid."))) + console.log( + error( + "Error parsing configuration file. Please check your .budibase.json is valid." + ) + ) + return {} } } @@ -30,7 +35,7 @@ class ConfigManager { setValue(key, value) { const updated = { ...this.config, - [key]: value + [key]: value, } this.config = updated } @@ -42,4 +47,4 @@ class ConfigManager { } } -module.exports = ConfigManager \ No newline at end of file +module.exports = ConfigManager