This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

18
node_modules/prompts/lib/index.js generated vendored
View File

@@ -2,7 +2,7 @@
const prompts = require('./prompts');
const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender'];
const passOn = ['suggest', 'format', 'onState', 'validate', 'onRender', 'type'];
const noop = () => {};
/**
@@ -16,7 +16,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
const answers = {};
const override = prompt._override || {};
questions = [].concat(questions);
let answer, question, quit, name, type;
let answer, question, quit, name, type, lastPrompt;
const getFormattedAnswer = async (question, answer, skipValidation = false) => {
if (!skipValidation && question.validate && question.validate(answer) !== true) {
@@ -28,13 +28,22 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
for (question of questions) {
({ name, type } = question);
// evaluate type first and skip if type is a falsy value
if (typeof type === 'function') {
type = await type(answer, { ...answers }, question)
question['type'] = type
}
if (!type) continue;
// if property is a function, invoke it unless it's a special function
for (let key in question) {
if (passOn.includes(key)) continue;
let value = question[key];
question[key] = typeof value === 'function' ? await value(answer, { ...answers }, question) : value;
question[key] = typeof value === 'function' ? await value(answer, { ...answers }, lastPrompt) : value;
}
lastPrompt = question;
if (typeof question.message !== 'string') {
throw new Error('prompt message is required');
}
@@ -42,9 +51,6 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
// update vars in case they changed
({ name, type } = question);
// skip if type is a falsy value
if (!type) continue;
if (prompts[type] === void 0) {
throw new Error(`prompt type (${type}) is not defined`);
}