Charles Lyding 985dc1a4c7 feat(@angular/cli): confirm ng add action before installation
BREAKING CHANGE:
The `ng add` command will now ask the user to confirm the package and version prior to installing and executing an uninstalled package.
This new behavior allows a user to abort the action if the version selected is not appropriate or if a typo occurred on the command line and an incorrect package would be installed.
A `--skip-confirmation` option has been added to skip the prompt and directly install and execute the package. This option is useful in CI and non-TTY scenarios such as automated scripts.
2021-03-11 08:54:07 +01:00

32 lines
718 B
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as inquirer from 'inquirer';
import { isTTY } from './tty';
export async function askConfirmation(
message: string,
defaultResponse: boolean,
noTTYResponse?: boolean,
): Promise<boolean> {
if (!isTTY()) {
return noTTYResponse ?? defaultResponse;
}
const question: inquirer.Question = {
type: 'confirm',
name: 'confirmation',
prefix: '',
message,
default: defaultResponse,
};
const answers = await inquirer.prompt([question]);
return answers['confirmation'];
}