UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

38 lines 1.45 kB
import path from "node:path"; import { exists, readJsonFile, writeJsonFile, } from "@nomicfoundation/hardhat-utils/fs"; import { getTelemetryDir } from "@nomicfoundation/hardhat-utils/global-dir"; import debug from "debug"; const log = debug("hardhat:cli:telemetry:analytics:utils"); const ANALYTICS_FILE_NAME = "analytics.json"; export async function getAnalyticsClientId() { let clientId = await readAnalyticsClientId(); if (clientId === undefined) { log("Client Id not found, generating a new one"); clientId = crypto.randomUUID(); await writeAnalyticsClientId(clientId); } return clientId; } async function readAnalyticsClientId() { const globalTelemetryDir = await getTelemetryDir(); const filePath = path.join(globalTelemetryDir, ANALYTICS_FILE_NAME); log(`Looking up Client Id at '${filePath}'`); if ((await exists(filePath)) === false) { return undefined; } const data = await readJsonFile(filePath); const clientId = data.analytics.clientId; log(`Client Id found: ${clientId}`); return clientId; } async function writeAnalyticsClientId(clientId) { const globalTelemetryDir = await getTelemetryDir(); const filePath = path.join(globalTelemetryDir, ANALYTICS_FILE_NAME); await writeJsonFile(filePath, { analytics: { clientId, }, }); log(`Stored clientId '${clientId}'`); } //# sourceMappingURL=utils.js.map