Freyskeyd/gulp-prompt

Not possible to pass the answer object from prompt method into next piped stream.

leftstick opened this issue · 3 comments

Sometimes i need to ask end-user for response more than once, so both the source file object and answer object from prompt are required.

I'd like to have such a thing as following:

prompt: function(questions, callback) {

        return es.map(function(file, cb) {

            if (!questions instanceof Array) {
                questions = [questions];
            }

            if (typeof callback !== 'function') {
                callback = function() {};
            }

            inq.prompt(questions, function(res) {
                callback(res);
                cb(null, {
                    source: file,
                    answer: res
                });
            });

        });
    }

Do you have any idea about this requirement?

To expand on @Freyskeyd's answer, streams can only contain files when it comes to gulp. Due to this limitation, what you are proposing is essentially impossible.

You can, however, do something like:

gulp.src('./package.json')
    .pipe(prompt.prompt([
        {
            type: 'list',
            name: '1',
            message: 'Question 1',
            choices: ['choice']
        },
        {
            type: 'list',
            name: '2',
            message: 'Question 2',
            choices: ['choice']
        }
    ], function(val){

        //val.1 / val.2 are answers

        gulp.src('./anotherfile.js')
            .pipe(val.1);

    }));

From this example, I both utilized the array parameter input to ask multiple questions at once, then utilized the result of those questions in the callback function, under a new yet seamless pipe.

Good luck!

Thanks @jonathandelgado, that is really what i want. I just found it is already in the docs.

Thanks @Freyskeyd for pointing out the concept of gulp.