mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
feat(cli): allow disable telemetry
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { PostHog } from "posthog-node";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import { getLatestCLIVersion } from "./get-latest-cli-version";
|
||||
import { isTelemetryEnabled } from "./telemetry";
|
||||
|
||||
const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
|
||||
const POSTHOG_HOST = process.env.POSTHOG_HOST;
|
||||
@@ -14,7 +15,7 @@ export async function trackProjectCreation(
|
||||
flushInterval: 0,
|
||||
privacyMode: true,
|
||||
disableGeoip: true,
|
||||
disabled: process.env.TELEMETRY !== "true",
|
||||
disabled: !isTelemetryEnabled(),
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
34
apps/cli/src/utils/telemetry.ts
Normal file
34
apps/cli/src/utils/telemetry.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Utility function to determine if telemetry should be enabled.
|
||||
*
|
||||
* Telemetry is enabled by default in production, but can be disabled by:
|
||||
* - Setting BTS_TELEMETRY=0 or BTS_TELEMETRY=false
|
||||
* - Running in development environment (NODE_ENV=development)
|
||||
*/
|
||||
export function isTelemetryEnabled(): boolean {
|
||||
// If user explicitly disabled telemetry
|
||||
if (
|
||||
process.env.BTS_TELEMETRY === "0" ||
|
||||
process.env.BTS_TELEMETRY === "false"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If user explicitly enabled telemetry
|
||||
if (
|
||||
process.env.BTS_TELEMETRY === "1" ||
|
||||
process.env.BTS_TELEMETRY === "true"
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
process.env.BTS_TELEMETRY_DISABLED === "1" ||
|
||||
process.env.BTS_TELEMETRY_DISABLED === "true"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Default to enabled in production
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user