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

Commit

Permalink
feature: adding telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
DamilolaAlao committed Jul 7, 2024
1 parent 4d52124 commit 28e7aa3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
33 changes: 33 additions & 0 deletions lib/cmd-fns/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ 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'

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

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

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

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 @@ -117,14 +134,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 @@ -60,6 +60,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 @@ -71,16 +72,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

0 comments on commit 28e7aa3

Please sign in to comment.