lint ✨
This commit is contained in:
parent
a4486fff4c
commit
7bc7fc7e7d
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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'"))
|
||||
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(
|
||||
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!"))
|
||||
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(
|
||||
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.",
|
||||
|
|
|
@ -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
|
|
@ -77,8 +77,8 @@ async function init(type) {
|
|||
distinctId: "cli",
|
||||
event: AnalyticsEvents.SelfHostInit,
|
||||
properties: {
|
||||
type
|
||||
}
|
||||
type,
|
||||
},
|
||||
})
|
||||
await downloadFiles()
|
||||
const config = isQuick ? makeEnv.QUICK_CONFIG : {}
|
||||
|
|
|
@ -15,7 +15,12 @@ class ConfigManager {
|
|||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue