frontend/.pnpm-store/v3/files/09/82535c27f218bc4795fb655efad8a5dca0b1454e3e55d82483faa40409096448a71d44136be3d50a77d091d76a8de10904fb2c3652a67f69656d365d121411

34 lines
1.0 KiB
Plaintext

const inquirer = require('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;
}
}
module.exports = Prompt;