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

Use prompt without pipe #22

Closed
renanhenrique opened this issue Oct 29, 2015 · 5 comments
Closed

Use prompt without pipe #22

renanhenrique opened this issue Oct 29, 2015 · 5 comments

Comments

@renanhenrique
Copy link

Hi, take a look @ this code:

gulp.task('install', function(){
  gulp.src('config/db.js')
  .pipe(
    gp_prompt.prompt(
      { type: 'input'
      , name: 'dbname'
      , message: 'Type your DB name:'
      },
      function (res){
        gulp.src('config./db.js')
        .pipe(gp_replace('_DBNAME_', res.dbname))
        .pipe(savefile())
      }
    )
  )
});

There's a way to use gulp-prompt without open 2 gulp.src('config/db.js') ?

@strunkie30
Copy link

I think that this Is not posible.
I use gulp.src('package.json') but it is ugly and slowing down the init.

@codyrushing
Copy link

I haven't really investigated why this works, but if you call .write() on the prompt stream, it will work:

gulp.task('install', function(){
  var prompter = gp_prompt.prompt(
    { type: 'input'
    , name: 'dbname'
    , message: 'Type your DB name:'
    },
    function (res){
      gulp.src('config./db.js')
      .pipe(gp_replace('_DBNAME_', res.dbname))
      .pipe(savefile())
    }
  )

  prompter.write()
  return prompter()
});

This probably has something to do with gulp not liking the Stream that Inquirer is returning

@yuricamara
Copy link

I miss this feature too.

I tried a confirm question with write(), @codyrushing . It didn't work as expected for me. The task was finished and then the question shown up.

@yuricamara
Copy link

Solved with Inquirer.js which is the library used by gulp-prompt

Example:

Both stop the gulp execution when the answer is 'no'.

//gulp-prompt
gulp.task('prompt', () => {
  const question = {
    message : 'Do you want to continue?(no)',
    default : false
  };

  return gulp.src('file')
    .pipe(prompt.confirm(question));
});
//Inquirer.js
gulp.task('prompt', () => {
  const question = [
    {
      type : 'confirm',
      name : 'continue',
      message : 'Do you want to continue?(no)',
      default : false
    }
  ];

  return inquirer.prompt(question).then(answer => {
    if (!answer.continue) {
      return process.exit (2);
    }
  });
});

This was referenced Jul 12, 2016
@shannonlal
Copy link
Collaborator

I am going to close this issue out since yuricamara seems to have provided a solution. If there is still any outstanding questions or concerns please let me know.

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

5 participants