Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

feature: adding telemetry #70

Merged
merged 6 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/cmd-fns/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ import { startEditEventWatcher } from "./start-edit-event-watcher"
import { startExportRequestWatcher } from "./start-export-request-watcher"
import { startFsWatcher } from "./start-fs-watcher"
import { uploadExamplesFromDirectory } from "./upload-examples-from-directory"
import { PostHog } from "posthog-node"
import crypto from 'crypto'

declare const POSTHOG_API_KEY: string;

const posthog = new PostHog(
POSTHOG_API_KEY,
{ host: 'https://us.i.posthog.com' }
)

export const devCmd = async (ctx: AppContext, args: any) => {
const params = z
Expand All @@ -27,6 +36,16 @@ export const devCmd = async (ctx: AppContext, args: any) => {
const { port } = params
const { cwd } = ctx

const projectHash = crypto.createHash('md5').update(cwd).digest('hex')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh this is a nice method


posthog.capture({
distinctId: projectHash,
event: 'tsci_dev_started',
properties: {
port: port,
}
})

// In the future we should automatically run "tsci init" if the directory
// isn't properly initialized, for now we're just going to do a spot check
const isInitialized = await checkIfInitialized(ctx)
Expand Down Expand Up @@ -120,14 +139,30 @@ export const devCmd = async (ctx: AppContext, args: any) => {
})
if (action === "open-in-browser") {
open(serverUrl)
posthog.capture({
distinctId: projectHash,
event: 'tsci_dev_open_browser'
})
} else if (action === "open-in-vs-code") {
await $`code ${cwd}`
posthog.capture({
distinctId: projectHash,
event: 'tsci_dev_open_vscode'
})
} else if (!action || action === "stop") {
if (server.stop) server.stop()
if (server.close) server.close()
fs_watcher.stop()
er_watcher.stop()
ee_watcher.stop()

posthog.capture({
distinctId: projectHash,
event: 'tsci_dev_stopped'
})

await posthog.shutdown()

break
}
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"node-persist": "^4.0.1",
"open": "^10.1.0",
"perfect-cli": "^1.0.20",
"posthog-node": "^4.0.1",
"prompts": "^2.4.2",
"react": "^18.2.0",
"semver": "^7.6.0",
Expand All @@ -70,16 +71,16 @@
"peerDependencies": {
"@tscircuit/builder": "*",
"@tscircuit/layout": "*",
"@tscircuit/manual-edit-events": "*",
"@tscircuit/react-fiber": "*",
"@tscircuit/soup-util": "*",
"@tscircuit/manual-edit-events": "*"
"@tscircuit/soup-util": "*"
},
"devDependencies": {
"@tscircuit/builder": "*",
"@tscircuit/layout": "^0.0.24",
"@tscircuit/manual-edit-events": "^0.0.4",
"@tscircuit/react-fiber": "*",
"@tscircuit/soup-util": "^0.0.11",
"@tscircuit/manual-edit-events": "^0.0.4",
"@types/archiver": "^6.0.2",
"@types/bun": "^1.0.8",
"@types/chokidar": "^2.1.3",
Expand Down
7 changes: 7 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'tsup'

export default defineConfig({
define: {
POSTHOG_API_KEY: JSON.stringify(process.env.POSTHOG_API_KEY || ''),
},
})
Loading