diff --git a/src/deployer.ts b/src/deployer.ts index 4f9e921a9..2c88ff19c 100644 --- a/src/deployer.ts +++ b/src/deployer.ts @@ -8,6 +8,8 @@ import { EventEmitter } from 'events'; import { Dictionary, Nullable } from '@salesforce/ts-types'; import cli from 'cli-ux'; +import { QuestionCollection } from 'inquirer'; +import { Prompter } from './prompter'; export interface Preferences { interactive: boolean; @@ -28,8 +30,8 @@ export abstract class Deployable { */ export abstract class Deployer extends EventEmitter { public deployables: Deployable[] = []; + private prompter = new Prompter(); - // Standard methods implemented in the base class methods // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function public progress(current: number, total: number, message: string): void {} @@ -37,6 +39,11 @@ export abstract class Deployer extends EventEmitter { cli.log(msg, ...args); } + public async prompt(questions: QuestionCollection, initialAnswers?: Partial): Promise { + const answers = await this.prompter.prompt(questions, initialAnswers); + return answers; + } + public selectDeployables(deployables: Deployable[]): void { this.deployables = Object.assign([], deployables); } diff --git a/src/exported.ts b/src/exported.ts index 9335dce9c..b38a2bab2 100644 --- a/src/exported.ts +++ b/src/exported.ts @@ -7,3 +7,4 @@ export { generateTableChoices } from './util'; export { Deployable, Deployer, Options, Preferences } from './deployer'; +export { Prompter } from './prompter'; diff --git a/src/prompter.ts b/src/prompter.ts new file mode 100644 index 000000000..b5b185014 --- /dev/null +++ b/src/prompter.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { prompt, QuestionCollection } from 'inquirer'; + +export class Prompter { + public async prompt(questions: QuestionCollection, initialAnswers?: Partial): Promise { + const answers = await prompt(questions, initialAnswers); + return answers; + } +} + +export namespace Prompter { + export type Answers> = T & Record; +}