mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { NODE_ENV } from "@definitions/node";
|
|
import { ProjectTypes } from "@definitions/projectTypes";
|
|
import { ENV } from "@utils/env";
|
|
import { getOS } from "@utils/os";
|
|
import { getInstalledRefinePackages, getRefineProjectId } 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: ENV.NODE_ENV,
|
|
nodeVersion: process.version,
|
|
os: os.name,
|
|
osVersion: os.version,
|
|
command: process.argv[2],
|
|
packages: (await getInstalledRefinePackages()) || [],
|
|
projectFramework: getProjectType(),
|
|
projectId: getRefineProjectId(),
|
|
};
|
|
|
|
return data;
|
|
};
|
|
|
|
export const telemetryHook = async () => {
|
|
if (ENV.REFINE_NO_TELEMETRY === "true") return;
|
|
|
|
try {
|
|
const data = await getTelemetryData();
|
|
|
|
await fetch("https://telemetry.refine.dev/cli", {
|
|
method: "POST",
|
|
body: JSON.stringify(data),
|
|
headers: { "Content-Type": "application/json" },
|
|
});
|
|
} catch (error) {}
|
|
};
|