-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: opt in defaults to true and improved messaging
- Loading branch information
Showing
3 changed files
with
74 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 16 additions & 44 deletions
60
packages/composable-cli/src/lib/insights/opt-in-product-insights-middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,42 @@ | ||
import { CommandContext, RootCommandArguments } from "../../types/command" | ||
import { MiddlewareFunction } from "yargs" | ||
import { isOptedInsights, optInsights } from "../../util/has-opted-insights" | ||
import inquirer from "inquirer" | ||
import Conf from "conf" | ||
import { logging } from "@angular-devkit/core" | ||
|
||
const optInQuestion: inquirer.QuestionCollection = [ | ||
{ | ||
type: "confirm", | ||
name: "optIn", | ||
message: ` | ||
Welcome to Elastic Paths Composable CLI! | ||
This is a new tool. To help us improve, would you like to opt-in to error tracking? | ||
When you opt-in, we'll collect: | ||
- Commands you run with composable cli | ||
- Error messages | ||
Your data will be used solely for improving our tool. | ||
(Your data will be kept private) | ||
`, | ||
default: true, // You can set the default value to true or false as needed | ||
}, | ||
] | ||
import { renderInfo } from "../../commands/ui" | ||
import { outputContent, outputToken } from "../../commands/output" | ||
|
||
export function createOptInProductInsightsMiddleware( | ||
ctx: CommandContext, | ||
): MiddlewareFunction<RootCommandArguments> { | ||
return async function optInProductInsightsMiddleware( | ||
args: RootCommandArguments, | ||
) { | ||
const { store, logger } = ctx | ||
const { store } = ctx | ||
|
||
if (isOptedInsights(store) || isInsightsCommand(args)) { | ||
return | ||
} | ||
|
||
if (!args.interactive) { | ||
optInsights(store, false) | ||
optInsights(store, true) | ||
return | ||
} | ||
|
||
await promptOptInProductInsights(store, logger) | ||
renderInfo({ | ||
headline: "Improving our tools with your help", | ||
body: outputContent`This is a new tool. To help improve the experience we collect: | ||
- Commands you run with composable cli | ||
- Error messages | ||
Your data will be used solely for improving our tools and user experiences and will always be kept private. | ||
if you wish to opt out run ${outputToken.genericShellCommand("ep insights")} | ||
`.value, | ||
}) | ||
optInsights(store, true) | ||
return | ||
} | ||
} | ||
|
||
function isInsightsCommand(argv: any): boolean { | ||
return argv._[0] === "insights" | ||
} | ||
|
||
export async function promptOptInProductInsights( | ||
store: Conf, | ||
logger: logging.Logger, | ||
): Promise<void> { | ||
const answers = await inquirer.prompt(optInQuestion) | ||
|
||
if (answers.optIn) { | ||
logger.info("Thank you for opting in. Your data will be kept private.") | ||
} else { | ||
logger.info( | ||
"You have chosen not to opt-in. Your privacy will be fully respected.", | ||
) | ||
} | ||
|
||
optInsights(store, answers.optIn) | ||
} |