frontend/.pnpm-store/v3/files/83/b1bc30f0b0a0559122276abf463a40ca799e676bfbd477cdc332cf4f3c93a7706bae2c2ba45ead061e8ea90f7c71c372a20cce39f29e8d90245b7e4dbc38be

34 lines
1.0 KiB
Plaintext

import inquirer from 'inquirer';
class Prompt {
constructor({ container }) {
this.createPrompt = (container.inquirer || inquirer).prompt;
this.prompts = {};
}
register(pluginPrompts, namespace = 'default') {
this.prompts[namespace] = this.prompts[namespace] || {};
Object.assign(this.prompts[namespace], pluginPrompts);
}
async show({ enabled = true, prompt: promptName, namespace = 'default', task, context }) {
if (!enabled) return false;
const prompt = this.prompts[namespace][promptName];
const options = Object.assign({}, prompt, {
name: promptName,
message: prompt.message(context),
choices: 'choices' in prompt && prompt.choices(context),
transformer: 'transformer' in prompt && prompt.transformer(context)
});
const answers = await this.createPrompt([options]);
const doExecute = prompt.type === 'confirm' ? answers[promptName] : true;
return doExecute && task ? await task(answers[promptName]) : false;
}
}
export default Prompt;