forked from vercel/next.js
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-telemetry.ts
executable file
·96 lines (82 loc) · 2.34 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env node
import chalk from 'next/dist/compiled/chalk'
import arg from 'next/dist/compiled/arg/index.js'
import { printAndExit } from '../server/lib/utils'
import { cliCommand } from '../lib/commands'
import { Telemetry } from '../telemetry/storage'
import isError from '../lib/is-error'
const nextTelemetry: cliCommand = (argv) => {
const validArgs: arg.Spec = {
// Types
'--help': Boolean,
'--enable': Boolean,
'--disable': Boolean,
// Aliases
'-h': '--help',
}
let args: arg.Result<arg.Spec>
try {
args = arg(validArgs, { argv })
} catch (error) {
if (isError(error) && error.code === 'ARG_UNKNOWN_OPTION') {
return printAndExit(error.message, 1)
}
throw error
}
if (args['--help']) {
console.log(
`
Description
Allows you to control Next.js' telemetry collection
Usage
$ next telemetry [enable/disable]
You may pass the 'enable' or 'disable' argument to turn Next.js' telemetry collection on or off.
Learn more: ${chalk.cyan('https://nextjs.org/telemetry')}
`
)
return
}
const telemetry = new Telemetry({ distDir: process.cwd() })
let isEnabled = telemetry.isEnabled
if (args['--enable'] || args._[0] === 'enable') {
telemetry.setEnabled(true)
console.log(chalk.cyan('Success!'))
console.log()
isEnabled = true
} else if (args['--disable'] || args._[0] === 'disable') {
const path = telemetry.setEnabled(false)
if (isEnabled) {
console.log(
chalk.cyan(
`Your preference has been saved${path ? ` to ${path}` : ''}.`
)
)
} else {
console.log(
chalk.yellow(`Next.js' telemetry collection is already disabled.`)
)
}
console.log()
isEnabled = false
} else {
console.log(chalk.bold('Next.js Telemetry'))
console.log()
}
console.log(
`Status: ${
isEnabled ? chalk.bold.green('Enabled') : chalk.bold.red('Disabled')
}`
)
console.log()
if (isEnabled) {
console.log(
`Next.js telemetry is completely anonymous. Thank you for participating!`
)
} else {
console.log(`You have opted-out of Next.js' anonymous telemetry program.`)
console.log(`No data will be collected from your machine.`)
}
console.log(`Learn more: https://nextjs.org/telemetry`)
console.log()
}
export { nextTelemetry }