-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): send telemetry data from cli (#3067)
* feat(cli): send telemetry data from cli * chore(cli): remove debug code * fix(cli): fix typo in description * chore(cli): remove unused code * chore(cli): remove unneseceary async * feat(docs): add cli telemetry section * chore(cli): add changeset * fix(cli): get OS name from node-os package * fix(docs): furtger readings link * fix(docs): change dobule quote to backquote * chore(docs): change mdx to md * feat(docs): change cli telemetry description Co-authored-by: Ömer Faruk APLAK <omer@pankod.com>
- Loading branch information
1 parent
94876eb
commit 6f83ddb
Showing
11 changed files
with
220 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@pankod/refine-cli": minor | ||
--- | ||
|
||
Added: `whoami` command to `refine-cli`. It's shows details of the development environment. | ||
Added: telemetry to `refine-cli` commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getInstalledRefinePackages } from "@utils/package"; | ||
import { Command } from "commander"; | ||
import envinfo from "envinfo"; | ||
import ora from "ora"; | ||
|
||
const whoami = (program: Command) => { | ||
return program | ||
.command("whoami") | ||
.description("View the details of the development environment") | ||
.action(action); | ||
}; | ||
|
||
const action = async () => { | ||
const spinner = ora("Loading environment details...").start(); | ||
const info = await envinfo.run( | ||
{ | ||
System: ["OS", "CPU"], | ||
Binaries: ["Node", "Yarn", "npm"], | ||
Browsers: ["Chrome", "Firefox", "Safari"], | ||
}, | ||
{ showNotFound: true, markdown: true }, | ||
); | ||
|
||
const packages = await getInstalledRefinePackages(); | ||
const packagesMarkdown = packages | ||
.map((pkg) => { | ||
return ` - ${pkg.name}: ${pkg.version}`; | ||
}) | ||
.join("\n"); | ||
|
||
spinner.stop(); | ||
console.log(info); | ||
console.log("## Refine Packages:"); | ||
console.log(packagesMarkdown); | ||
}; | ||
|
||
export default whoami; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./projectTypes"; | ||
export * from "./uiFrameworks"; | ||
export * from "./package"; | ||
export * from "./node"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export type NODE_ENV = | ||
| "development" | ||
| "production" | ||
| "test" | ||
| "continuous-integration" | ||
| "system-integration-testing" | ||
| "user-acceptance-testing" | ||
| "custom"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { NODE_ENV } from "@definitions/node"; | ||
import { ProjectTypes } from "@definitions/projectTypes"; | ||
import { ENV, parseNodeEnv } from "@utils/env"; | ||
import { getOS } from "@utils/os"; | ||
import { getInstalledRefinePackages } from "@utils/package"; | ||
import { getProjectType } from "@utils/project"; | ||
import fetch from "node-fetch"; | ||
|
||
interface TelemetryData { | ||
nodeEnv?: NODE_ENV; | ||
nodeVersion: string; | ||
os: string; | ||
osVersion: string; | ||
command: string; | ||
packages: { | ||
name: string; | ||
version: string; | ||
}[]; | ||
projectFramework: ProjectTypes; | ||
} | ||
|
||
export const getTelemetryData = async (): Promise<TelemetryData> => { | ||
const os = await getOS(); | ||
|
||
const data = { | ||
nodeEnv: parseNodeEnv(), | ||
nodeVersion: process.version, | ||
os: os.name, | ||
osVersion: os.version, | ||
command: process.argv[2], | ||
packages: await getInstalledRefinePackages(), | ||
projectFramework: getProjectType(), | ||
}; | ||
|
||
return data; | ||
}; | ||
|
||
export const telemetryHook = async () => { | ||
if (ENV.REFINE_NO_TELEMETRY === "true") return; | ||
|
||
try { | ||
const data = await getTelemetryData(); | ||
|
||
fetch("https://telemetry.refine.dev/cli", { | ||
method: "POST", | ||
body: JSON.stringify(data), | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} catch (error) {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import { NODE_ENV } from "@definitions/node"; | ||
import { env } from "node-env-type"; | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
export const ENV = { | ||
REFINE_NO_TELEMETRY: process.env.REFINE_NO_TELEMETRY || "false", | ||
UPDATE_NOTIFIER_IS_DISABLED: | ||
process.env.UPDATE_NOTIFIER_IS_DISABLED || "false", | ||
UPDATE_NOTIFIER_CACHE_TTL: | ||
process.env.UPDATE_NOTIFIER_CACHE_TTL || 1000 * 60 * 60 * 24, // 24 hours, | ||
}; | ||
|
||
export const parseNodeEnv = (): NODE_ENV => { | ||
if (env.isDev) return "development"; | ||
if (env.isProd) return "production"; | ||
if (env.isTest) return "test"; | ||
if (env.isCI) return "continuous-integration"; | ||
if (env.isUAT) return "user-acceptance-testing"; | ||
if (env.isSIT) return "system-integration-testing"; | ||
|
||
return "custom"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import envinfo from "envinfo"; | ||
import os from "os"; | ||
|
||
export const getOSType = () => { | ||
const osPlatform = os.type(); | ||
|
||
const types: Record<string, "macOS" | "Linux" | "Windows"> = { | ||
Darwin: "macOS", | ||
Linux: "Linux", | ||
Windows_NT: "Windows", | ||
}; | ||
|
||
return types[osPlatform]; | ||
}; | ||
|
||
export const getOS = async () => { | ||
// returns as a ['OS', 'macOS Mojave 10.14.5'] | ||
const [_, OSInfo] = | ||
(await envinfo.helpers.getOSInfo()) as unknown as string[]; | ||
|
||
return { | ||
name: getOSType(), | ||
version: OSInfo, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters