mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
feat(cli): add disable analytics option (#496)
This commit is contained in:
5
.changeset/honest-results-tease.md
Normal file
5
.changeset/honest-results-tease.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"create-better-t-stack": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
add disable analytics option
|
||||||
@@ -178,7 +178,7 @@ export async function createProjectHandler(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
await trackProjectCreation(config);
|
await trackProjectCreation(config, input.disableAnalytics);
|
||||||
|
|
||||||
const elapsedTimeMs = Date.now() - startTime;
|
const elapsedTimeMs = Date.now() - startTime;
|
||||||
const elapsedTimeInSeconds = (elapsedTimeMs / 1000).toFixed(2);
|
const elapsedTimeInSeconds = (elapsedTimeMs / 1000).toFixed(2);
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ export const router = t.router({
|
|||||||
webDeploy: WebDeploySchema.optional(),
|
webDeploy: WebDeploySchema.optional(),
|
||||||
directoryConflict: DirectoryConflictSchema.optional(),
|
directoryConflict: DirectoryConflictSchema.optional(),
|
||||||
renderTitle: z.boolean().optional(),
|
renderTitle: z.boolean().optional(),
|
||||||
|
disableAnalytics: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.default(false)
|
||||||
|
.describe("Disable analytics"),
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
@@ -198,6 +203,7 @@ export function createBtsCli() {
|
|||||||
* packageManager: "bun",
|
* packageManager: "bun",
|
||||||
* install: false,
|
* install: false,
|
||||||
* directoryConflict: "increment", // auto-handle conflicts
|
* directoryConflict: "increment", // auto-handle conflicts
|
||||||
|
* disableAnalytics: true, // disable analytics
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* if (result.success) {
|
* if (result.success) {
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ export type CreateInput = {
|
|||||||
webDeploy?: WebDeploy;
|
webDeploy?: WebDeploy;
|
||||||
directoryConflict?: DirectoryConflict;
|
directoryConflict?: DirectoryConflict;
|
||||||
renderTitle?: boolean;
|
renderTitle?: boolean;
|
||||||
|
disableAnalytics?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AddInput = {
|
export type AddInput = {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { isTelemetryEnabled } from "./telemetry";
|
|||||||
const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
|
const POSTHOG_API_KEY = process.env.POSTHOG_API_KEY || "";
|
||||||
const POSTHOG_HOST = process.env.POSTHOG_HOST;
|
const POSTHOG_HOST = process.env.POSTHOG_HOST;
|
||||||
|
|
||||||
export async function trackProjectCreation(config: ProjectConfig) {
|
export async function trackProjectCreation(config: ProjectConfig, disableAnalytics = false) {
|
||||||
if (!isTelemetryEnabled()) return;
|
if (!isTelemetryEnabled() || disableAnalytics) return;
|
||||||
|
|
||||||
const sessionId = `cli_${crypto.randomUUID().replace(/-/g, "")}`;
|
const sessionId = `cli_${crypto.randomUUID().replace(/-/g, "")}`;
|
||||||
// biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties
|
// biome-ignore lint/correctness/noUnusedVariables: `projectName`, `projectDir`, and `relativePath` are not used in the event properties
|
||||||
|
|||||||
@@ -213,6 +213,18 @@ describe("Programmatic API - Fast Tests", () => {
|
|||||||
addons: ["biome"],
|
addons: ["biome"],
|
||||||
});
|
});
|
||||||
}, 15000);
|
}, 15000);
|
||||||
|
|
||||||
|
test("creates project with analytics disabled", async () => {
|
||||||
|
const result = await init("no-analytics-app", {
|
||||||
|
yes: true,
|
||||||
|
disableAnalytics: true,
|
||||||
|
install: false,
|
||||||
|
git: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
expect(result.projectConfig.projectName).toBe("no-analytics-app");
|
||||||
|
}, 15000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Error scenarios", () => {
|
describe("Error scenarios", () => {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ async function createProject() {
|
|||||||
auth: true,
|
auth: true,
|
||||||
packageManager: "bun",
|
packageManager: "bun",
|
||||||
install: false, // Don't install deps automatically
|
install: false, // Don't install deps automatically
|
||||||
|
disableAnalytics: true, // Disable analytics
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
@@ -62,6 +63,23 @@ const result = await init("existing-folder", {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Disabling Analytics
|
||||||
|
|
||||||
|
You can disable analytics:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { init } from "create-better-t-stack";
|
||||||
|
|
||||||
|
const result = await init("my-private-project", {
|
||||||
|
yes: true,
|
||||||
|
disableAnalytics: true, // No analytics data will be sent
|
||||||
|
frontend: ["tanstack-router"],
|
||||||
|
backend: "hono",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** Analytics help improve Better-T Stack by providing insights into usage patterns. When disabled, no data is collected or transmitted.
|
||||||
|
|
||||||
## API Reference
|
## API Reference
|
||||||
|
|
||||||
### `init(projectName?, options?)`
|
### `init(projectName?, options?)`
|
||||||
@@ -130,6 +148,7 @@ interface CreateInput {
|
|||||||
webDeploy?: WebDeploy; // Web deployment setup
|
webDeploy?: WebDeploy; // Web deployment setup
|
||||||
directoryConflict?: DirectoryConflict; // "merge" | "overwrite" | "increment" | "error"
|
directoryConflict?: DirectoryConflict; // "merge" | "overwrite" | "increment" | "error"
|
||||||
renderTitle?: boolean; // Show ASCII art title
|
renderTitle?: boolean; // Show ASCII art title
|
||||||
|
disableAnalytics?: boolean; // Disable analytics and telemetry
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user