yeoman-app icon indicating copy to clipboard operation
yeoman-app copied to clipboard

Issue with new yeoman-generator version

Open FrancoisDF opened this issue 7 years ago • 3 comments

I could not get any generators working that were using yeoman-generator@^1.0.0. I keep getting the following error:

TypeError: Cannot read property 'then' of undefined
    at <generator_name>.Base.prompt (.../node_modules/<generator_name>/node_modules/yeoman-generator/lib/index.js:168:44)

(generator-licence is an easy one to test)

FrancoisDF avatar Sep 11 '17 19:09 FrancoisDF

Starting from [email protected], Base#prompt() functions now returns a promise instead of taking a callback parameter:

prompting: function () {
   return this.prompt(questions).then(function (answers) {
    this.answers = answers;
  }.bind(this));
}

So I think the adapter need to be updated to use a promise instead of a callback. Or maybe returning both to be compatible with more generators.

FrancoisDF avatar Sep 11 '17 20:09 FrancoisDF

FIX In yo/adapter.js

ProcessAdapter.prototype.prompt = function (questions, callback) {
  process.send({
    event: 'generator:prompt-questions',
    data: questions
  });

  if (callback){
    this.answerCallback = callback;
  } else {
    return new Promise((resolve) => {
      this.answerCallback = resolve;
    });
  }
};

FrancoisDF avatar Sep 19 '17 01:09 FrancoisDF

@R0muald do you want to send a PR?

This project isn't actively maintained anymore, but I'll gladly help you get some fixes in.

SBoudrias avatar Sep 19 '17 02:09 SBoudrias