-
Notifications
You must be signed in to change notification settings - Fork 28k
/
Copy pathnext-telemetry.ts
executable file
·53 lines (42 loc) · 1.36 KB
/
next-telemetry.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
import { bold, cyan, green, red, yellow } from '../lib/picocolors'
import { Telemetry } from '../telemetry/storage'
type NextTelemetryOptions = {
enable?: boolean
disable?: boolean
}
const telemetry = new Telemetry({ distDir: process.cwd() })
let isEnabled = telemetry.isEnabled
const nextTelemetry = (options: NextTelemetryOptions, arg: string) => {
if (options.enable || arg === 'enable') {
telemetry.setEnabled(true)
isEnabled = true
console.log(cyan('Success!'))
} else if (options.disable || arg === 'disable') {
const path = telemetry.setEnabled(false)
if (isEnabled) {
console.log(
cyan(`Your preference has been saved${path ? ` to ${path}` : ''}.`)
)
} else {
console.log(yellow(`Next.js' telemetry collection is already disabled.`))
}
isEnabled = false
} else {
console.log(bold('Next.js Telemetry'))
}
console.log(
`\nStatus: ${isEnabled ? bold(green('Enabled')) : bold(red('Disabled'))}`
)
if (isEnabled) {
console.log(
'\nNext.js telemetry is completely anonymous. Thank you for participating!'
)
} else {
console.log(
`\nYou have opted-out of Next.js' anonymous telemetry program.\nNo data will be collected from your machine.`
)
}
console.log(`\nLearn more: ${cyan('https://nextjs.org/telemetry')}`)
}
export { nextTelemetry }