Skip to content

Commit

Permalink
Continue converting base to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
jamo committed Jul 20, 2020
1 parent 0315737 commit 63acc67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 307 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const boxen = require(`boxen`)
import boxen, { BorderStyle } from "boxen"

const defaultConfig = {
padding: 1,
borderColor: `blue`,
borderStyle: `double`,
borderStyle: BorderStyle.Double,
}

const defaultMessage =
Expand All @@ -15,14 +15,10 @@ const defaultMessage =

/**
* Analytics notice for the end-user
* @param {Object} config - The configuration that boxen accepts. https://github.com/sindresorhus/boxen#api
* @param {string} message - Message shown to the end-user
*/
const showAnalyticsNotification = (
config = defaultConfig,
message = defaultMessage
) => {
export function showAnalyticsNotification(
config: boxen.Options = defaultConfig,
message: string = defaultMessage
): void {
console.log(boxen(message, config))
}

module.exports = showAnalyticsNotification
283 changes: 0 additions & 283 deletions packages/gatsby-telemetry/src/telemetry.js

This file was deleted.

32 changes: 18 additions & 14 deletions packages/gatsby-telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
const uuidv4 = require(`uuid/v4`)
const EventStorage = require(`./event-storage`)
const { cleanPaths } = require(`./error-helpers`)
const { isCI, getCIName } = require(`gatsby-core-utils`)
const os = require(`os`)
const { join, sep } = require(`path`)
const isDocker = require(`is-docker`)
const showAnalyticsNotification = require(`./showAnalyticsNotification`)
const lodash = require(`lodash`)
const dbEngine = `redux`
import uuidV4 from "uuid/v4"
import { isCI, getCIName } from "gatsby-core-utils"

import {
getRepositoryId as _getRepositoryId,
IRepositoryId,
} from "./repository-id"
import os from "os"

import { join, sep } from "path"
import isDocker from "is-docker"
import { showAnalyticsNotification } from "./show-analytics-notification"
import lodash from "lodash"

// TODO convert to TypeScript
const EventStorage = require(`./event-storage`)
const { cleanPaths } = require(`./error-helpers`)

const dbEngine = `redux`

type UUID = string
type SemVer = string | undefined
Expand All @@ -39,7 +43,7 @@ interface IAggregateStats {
skewness: number
}

module.exports = class AnalyticsTracker {
export class AnalyticsTracker {
store = new EventStorage()
debouncer = {}
metadataCache = {}
Expand Down Expand Up @@ -75,7 +79,7 @@ module.exports = class AnalyticsTracker {
getSessionId(): UUID {
return (
process.gatsbyTelemetrySessionId ||
(process.gatsbyTelemetrySessionId = uuidv4())
(process.gatsbyTelemetrySessionId = uuidV4())
)
}

Expand All @@ -86,7 +90,7 @@ module.exports = class AnalyticsTracker {
return this.repositoryId
}

getTagsFromEnv(): Record<string, any> {
getTagsFromEnv(): Record<string, unknown> {
if (process.env.GATSBY_TELEMETRY_TAGS) {
try {
return JSON.parse(process.env.GATSBY_TELEMETRY_TAGS)
Expand Down Expand Up @@ -236,7 +240,7 @@ module.exports = class AnalyticsTracker {
}
let machineId = this.store.getConfig(`telemetry.machineId`)
if (!machineId) {
machineId = uuidv4()
machineId = uuidV4()
this.store.updateConfig(`telemetry.machineId`, machineId)
}
this.machineId = machineId
Expand Down

0 comments on commit 63acc67

Please sign in to comment.