aboutsummaryrefslogtreecommitdiff
path: root/scripts/telemetry.js
blob: 78bf54fd31f585e39c74748e61547048942397be (plain) (blame)
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
import os from 'node:os';
import path from 'node:path';
import isCI from 'is-ci';
import { createRequire } from 'module';

const require = createRequire(import.meta.url);
const pkg = require(path.resolve(process.cwd(), 'package.json'));

const url = 'https://api.umami.is/v1/telemetry';

export async function sendTelemetry(type) {
  const { default: isDocker } = await import('is-docker');
  const { default: fetch } = await import('node-fetch');

  const data = {
    type,
    payload: {
      version: pkg.version,
      node: process.version,
      platform: os.platform(),
      arch: os.arch(),
      os: `${os.type()} ${os.version()}`,
      is_docker: isDocker(),
      is_ci: isCI,
    },
  };

  try {
    await fetch(url, {
      method: 'post',
      cache: 'no-cache',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
    });
  } catch {
    // Ignore
  }
}