Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confirm - no kills whole sequence not just current task in sequence #61

Open
reintroducing opened this issue Jun 22, 2018 · 9 comments
Open

Comments

@reintroducing
Copy link

I have a set of tasks that are run in sequence using run-sequence:

const gulp = require('gulp');
const sequence = require('run-sequence');

const setupTask = cb => {
    sequence(
        'updatePackageScripts',
        'installPeerDeps',
        'scaffoldConfigs',
        'scaffoldProject',
        cb
    );
};

gulp.task('setup', setupTask);

module.exports = setupTask;

In the installPeerDeps task, I'm using gulp-prompt:

const peerDependenciesTask = () => {
    const peers = keys(mapKeys(packageJSON.peerDependencies, (value, key) => {
        return `${key}@${value}`;
    })).join(' ');

    return gulp.src(`${projectPath(global.SETTINGS_CONFIG.root.path)}/package.json`, {read: false})
        .pipe(prompt.confirm({
            message: 'Also install peerDependencies? (Required when starting a new project with ACE)',
            default: true
        }))
        .pipe(shell([
            `npm install -S ${peers}`
        ], {
            cwd: process.env.INIT_CWD
        }));
};

This works great, however, if I say n to the subsequent prompt, I'd expect it to exit out of this task and continue with the next task in the sequence, scaffoldConfigs, rather than completely exiting the setup task.

Am I missing something that does this? Or is this the expected behavior and I won't be able to use gulp-prompt for this?

@reintroducing
Copy link
Author

Anyone? @shannonlal is this project still maintained?

@shannonlal
Copy link
Collaborator

@reintroducing can you provide a sample gulpfile to test

@shannonlal
Copy link
Collaborator

@reintroducing. The normal flow for it to exit is to return undefined. If you look under the examples directory at the file examples/chain-confirm-gulp.js that when the function stops when the chainFunction returns undefined.

var chainFunction = function ( options, resp ){
    console.log( 'Here is the selection ', resp);
    if( index <= 3){
        options.message = `Hello this is iteration ${index}`;
        index++;
        return options;
    }else{
        return; //Returning undefined stops the chaining process
    }
};

@reintroducing
Copy link
Author

@shannonlal Here is an example: https://www.dropbox.com/s/2gngxpcpc7xi7ed/gulp-prompt-test.zip?dl=0

Just download, npm install, and npm start.

What i would expect to happen is that task2 and task3 still run because you're saying no to the current task in the sequence, that being that you don't want to copy the files for that task. its possible that i'm missing the point of this package, though, so just wanted to get a second pair of eyes on this.

@shannonlal
Copy link
Collaborator

@reintroducing gulp-prompt allows a user to prompt for user for input but in order to chain them you need to look at adding a chainFunction. See the example (Example Chaining Prompts: in ReadMe file). This will allow you to link multiple user inputs in sequence. With a chain function you essentially take control of the logic as to what questions to ask the user and when to end the sequence.

If I go to you initial question it looks like you want to ask the user four questions and do different behaviours based on the inputs. The chain function support will allow you to do this. It is essentially a recursive function that allows you to control the options (i.e. passed to the prompt) from prompt to prompt. The chain function will essentially intercept the result of each prompt, allow the developer to manipulate the options, and send them to the next prompt. When you return undefined it will exit the chain function.

Let me know if that answers your questions

@reintroducing
Copy link
Author

@shannonlal I apologize, I should have been clearer in my prior post. I tried the chainer according to the example you originally pointed out and changed task1.js to the following:

const gulp = require('gulp');
const prompt = require('gulp-prompt');

const chainer = (options, resp) => {
    console.log('value: ', resp.val, typeof resp.val);

    if (resp.val) {
        return options;
    } else {
        return;
    }
};

gulp.task('task1', () => {
    return gulp.src('file.js')
        .pipe(prompt.confirm({
            message: 'Should we proceed to task 2?',
            default: true,
            chainFunction: chainer
        }, res => {
            console.log('RESULT:', res);
        }))
        .pipe(gulp.dest('dist'))
        .on('end', () => {
            console.log('im done');
        });
});

This essentially puts me in an endless loop if i answer Y and ends the sequence if I say n. I can't figure out how to get it to go to the next task no matter what is answered, but ideally i'd like to proceed to task2 regardless of the answer, and if they answer Y then go ahead and copy the file (the next pipe statement) and if n then don't copy but still move on in the original sequence in my default task. I also never see the RESULT log.

Does that make sense?

@shannonlal
Copy link
Collaborator

@reintroducing So you are trying to chain to independent gulp tasks. Is this correct? I use this on my internal project at work. I use run-sequence combined with gulp-prompt to collect parameters and then pass those parameters to other gulp tasks. Can you update the attached file to have task1 and task 2 defined and how you would expect to run them together.

@reintroducing
Copy link
Author

reintroducing commented Aug 1, 2018

@shannonlal I don't actually need task2 to take anything from task1. i just want task2 to run still if i say 'no' to task1. only thing i need is this, pseudo code:

if (yes to task1 then finish task1 and move to task2) else if (no to task1 then don't execute rest of task1 and move to task2) and so on until all tasks in the sequence have finished.

@reintroducing
Copy link
Author

@shannonlal Is there anything else you need me to do to try and help track this down? Does my prior message make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants