forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrack-command-copy.ts
More file actions
50 lines (45 loc) · 1.01 KB
/
Copy pathtrack-command-copy.ts
File metadata and controls
50 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { PostHog } from "posthog-js";
const KNOWN_INSTALL_TYPES = [
"npx",
"npm",
"pnpm",
"yarn",
"bun",
"pip",
"uv",
"poetry",
"cargo",
"go",
"docker",
"curl",
"brew",
"helm",
"kubectl",
"make",
"bash",
"sh",
] as const;
export type InstallType = (typeof KNOWN_INSTALL_TYPES)[number] | "code";
function inferInstallType(command: string): InstallType {
const firstToken = command.trim().split(/\s+/)[0]?.toLowerCase();
if (!firstToken) return "code";
return (KNOWN_INSTALL_TYPES as readonly string[]).includes(firstToken)
? (firstToken as InstallType)
: "code";
}
export type TrackCommandCopyArgs = {
command: string;
location?: string;
};
export function trackCommandCopy(
posthog: PostHog | undefined,
{ command, location }: TrackCommandCopyArgs,
) {
if (!posthog) return;
const trimmed = command.trim();
if (!trimmed) return;
posthog.capture("cli_command_copied", {
install_type: inferInstallType(trimmed),
...(location ? { location } : {}),
});
}