mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
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.
32 lines
718 B
TypeScript
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'];
|
|
}
|