2019-08-29 18:43:06 +02:00
|
|
|
#!/usr/bin/env node
|
2020-11-06 03:33:14 +01:00
|
|
|
import chalk from 'chalk'
|
2019-08-29 18:43:06 +02:00
|
|
|
import arg from 'next/dist/compiled/arg/index.js'
|
2020-07-28 12:12:57 +02:00
|
|
|
import { printAndExit } from '../server/lib/utils'
|
2019-08-29 18:43:06 +02:00
|
|
|
import { cliCommand } from '../bin/next'
|
2019-10-10 19:18:07 +02:00
|
|
|
import { Telemetry } from '../telemetry/storage'
|
2019-08-29 18:43:06 +02:00
|
|
|
|
2020-05-18 21:24:37 +02:00
|
|
|
const nextTelemetry: cliCommand = (argv) => {
|
2020-07-28 12:12:57 +02:00
|
|
|
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 (error.code === 'ARG_UNKNOWN_OPTION') {
|
|
|
|
return printAndExit(error.message, 1)
|
|
|
|
}
|
|
|
|
throw error
|
|
|
|
}
|
2019-08-29 18:43:06 +02:00
|
|
|
|
|
|
|
if (args['--help']) {
|
|
|
|
console.log(
|
|
|
|
`
|
|
|
|
Description
|
|
|
|
Allows you to control Next.js' telemetry collection
|
|
|
|
|
|
|
|
Usage
|
2019-09-10 18:31:18 +02:00
|
|
|
$ next telemetry [enable/disable]
|
2019-08-29 18:43:06 +02:00
|
|
|
|
2019-09-10 18:31:18 +02:00
|
|
|
You may pass the 'enable' or 'disable' argument to turn Next.js' telemetry collection on or off.
|
2019-08-29 18:43:06 +02:00
|
|
|
|
|
|
|
Learn more: ${chalk.cyan('https://nextjs.org/telemetry')}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:18:07 +02:00
|
|
|
const telemetry = new Telemetry({ distDir: process.cwd() })
|
|
|
|
|
|
|
|
let isEnabled = telemetry.isEnabled
|
2019-09-10 18:31:18 +02:00
|
|
|
|
|
|
|
if (args['--enable'] || args._[0] === 'enable') {
|
2019-10-10 19:18:07 +02:00
|
|
|
telemetry.setEnabled(true)
|
2019-08-29 18:43:06 +02:00
|
|
|
console.log(chalk.cyan('Success!'))
|
|
|
|
console.log()
|
2019-09-10 18:31:18 +02:00
|
|
|
|
|
|
|
isEnabled = true
|
|
|
|
} else if (args['--disable'] || args._[0] === 'disable') {
|
2019-10-10 19:18:07 +02:00
|
|
|
telemetry.setEnabled(false)
|
2019-09-10 18:31:18 +02:00
|
|
|
if (isEnabled) {
|
|
|
|
console.log(chalk.cyan('Your preference has been saved.'))
|
|
|
|
} else {
|
|
|
|
console.log(
|
|
|
|
chalk.yellow(`Next.js' telemetry collection is already disabled.`)
|
|
|
|
)
|
|
|
|
}
|
2019-08-29 18:43:06 +02:00
|
|
|
console.log()
|
2019-09-10 18:31:18 +02:00
|
|
|
|
|
|
|
isEnabled = false
|
2019-08-29 18:43:06 +02:00
|
|
|
} 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 }
|