feat: medusa-telemetry (#328)

* feat: adds a telemetry package to collect anonymous usage data

* fix: update telemetry host

* fix: adds medusa telemetry --disable

* fix: add tracking of link,login,new

* fix: interactively collect db credentials

* fix: require seed file

* fix: removes tracking from reporter
This commit is contained in:
Sebastian Rindom
2021-08-05 12:23:05 +02:00
committed by GitHub
parent f07cc0fa40
commit cfe19f7f9d
29 changed files with 6509 additions and 58 deletions

View File

@@ -2,10 +2,12 @@ const path = require(`path`)
const resolveCwd = require(`resolve-cwd`)
const yargs = require(`yargs`)
const existsSync = require(`fs-exists-cached`).sync
const { setTelemetryEnabled } = require("medusa-telemetry")
const { getLocalMedusaVersion } = require(`./util/version`)
const { didYouMean } = require(`./did-you-mean`)
const reporter = require("./reporter").default
const { newStarter } = require("./commands/new")
const { whoami } = require("./commands/whoami")
const { login } = require("./commands/login")
@@ -61,7 +63,6 @@ function buildLocalCommands(cli, isLocalProject) {
const localCmd = resolveLocalCommand(command)
const args = { ...argv, ...projectInfo, useYarn }
// report.verbose(`running command: ${command}`)
return handler ? handler(args, localCmd) : localCmd(args)
}
}
@@ -75,6 +76,12 @@ function buildLocalCommands(cli, isLocalProject) {
describe: `If flag is set the command will attempt to seed the database after setup.`,
default: false,
})
.option(`y`, {
type: `boolean`,
alias: "useDefaults",
describe: `If flag is set the command will not interactively collect database credentials`,
default: false,
})
.option(`skip-db`, {
type: `boolean`,
describe: `If flag is set the command will not attempt to complete database setup`,
@@ -118,6 +125,28 @@ function buildLocalCommands(cli, isLocalProject) {
desc: `Create a new Medusa project.`,
handler: handlerP(newStarter),
})
.command({
command: `telemetry`,
describe: `Enable or disable collection of anonymous usage data.`,
builder: yargs =>
yargs
.option(`enable`, {
type: `boolean`,
description: `Enable telemetry (default)`,
})
.option(`disable`, {
type: `boolean`,
description: `Disable telemetry`,
}),
handler: handlerP(({ enable, disable }) => {
const enabled = Boolean(enable) || !disable
setTelemetryEnabled(enabled)
reporter.info(
`Telemetry collection ${enabled ? `enabled` : `disabled`}`
)
}),
})
.command({
command: `seed`,
desc: `Migrates and populates the database with the provided file.`,
@@ -126,6 +155,7 @@ function buildLocalCommands(cli, isLocalProject) {
alias: `seed-file`,
type: `string`,
describe: `Path to the file where the seed is defined.`,
required: true,
}).option(`m`, {
alias: `migrate`,
type: `boolean`,
@@ -364,8 +394,8 @@ module.exports = argv => {
const suggestion = arg ? didYouMean(arg, availableCommands) : ``
cli.showHelp()
// report.log(suggestion)
// report.log(msg)
reporter.info(suggestion)
reporter.info(msg)
})
.parse(argv.slice(2))
}