Skip to content

Commit c79a513

Browse files
committed
refactor(@angular/cli): use prompt helper functions in analytics and completion commands
Instead of manually invoking an underlying prompt library, the analytics and completion commands now use the helper utility functions present to handle console prompts.
1 parent cb18da3 commit c79a513

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

packages/angular/cli/src/analytics/analytics.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { CommandContext } from '../command-builder/command-module';
1212
import { colors } from '../utilities/color';
1313
import { getWorkspace } from '../utilities/config';
1414
import { analyticsDisabled } from '../utilities/environment-options';
15-
import { loadEsmModule } from '../utilities/load-esm';
15+
import { askConfirmation } from '../utilities/prompt';
1616
import { isTTY } from '../utilities/tty';
1717

1818
/* eslint-disable no-console */
@@ -75,24 +75,19 @@ export async function promptAnalytics(
7575
}
7676

7777
if (force || isTTY()) {
78-
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
79-
const answers = await inquirer.prompt<{ analytics: boolean }>([
80-
{
81-
type: 'confirm',
82-
name: 'analytics',
83-
message: tags.stripIndents`
84-
Would you like to share pseudonymous usage data about this project with the Angular Team
85-
at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
86-
details and how to change this setting, see https://angular.io/analytics.
87-
88-
`,
89-
default: false,
90-
},
91-
]);
92-
93-
await setAnalyticsConfig(global, answers.analytics);
94-
95-
if (answers.analytics) {
78+
const answer = await askConfirmation(
79+
`
80+
Would you like to share pseudonymous usage data about this project with the Angular Team
81+
at Google under Google's Privacy Policy at https://policies.google.com/privacy. For more
82+
details and how to change this setting, see https://angular.io/analytics.
83+
84+
`,
85+
false,
86+
);
87+
88+
await setAnalyticsConfig(global, answer);
89+
90+
if (answer) {
9691
console.log('');
9792
console.log(
9893
tags.stripIndent`

packages/angular/cli/src/utilities/completion.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getWorkspace } from '../utilities/config';
1616
import { forceAutocomplete } from '../utilities/environment-options';
1717
import { isTTY } from '../utilities/tty';
1818
import { assertIsError } from './error';
19-
import { loadEsmModule } from './load-esm';
19+
import { askConfirmation } from './prompt';
2020

2121
/** Interface for the autocompletion configuration stored in the global workspace. */
2222
interface CompletionConfig {
@@ -179,24 +179,17 @@ async function shouldPromptForAutocompletionSetup(
179179
}
180180

181181
async function promptForAutocompletion(): Promise<boolean> {
182-
// Dynamically load `inquirer` so users don't have to pay the cost of parsing and executing it for
183-
// the 99% of builds that *don't* prompt for autocompletion.
184-
const { default: inquirer } = await loadEsmModule<typeof import('inquirer')>('inquirer');
185-
const { autocomplete } = await inquirer.prompt<{ autocomplete: boolean }>([
186-
{
187-
name: 'autocomplete',
188-
type: 'confirm',
189-
message: `
182+
const autocomplete = await askConfirmation(
183+
`
190184
Would you like to enable autocompletion? This will set up your terminal so pressing TAB while typing
191185
Angular CLI commands will show possible options and autocomplete arguments. (Enabling autocompletion
192186
will modify configuration files in your home directory.)
193-
`
194-
.split('\n')
195-
.join(' ')
196-
.trim(),
197-
default: true,
198-
},
199-
]);
187+
`
188+
.split('\n')
189+
.join(' ')
190+
.trim(),
191+
true,
192+
);
200193

201194
return autocomplete;
202195
}

0 commit comments

Comments
 (0)