What I'm trying to do is ask a question only if a field is set to true in the prompt.
this.prompt(prompts, function (props) {
this.isShared = props.isShared;
this.componentName = props.componentName;
// To access props later use this.props.someAnswer;
if (this.isShared)
{
prompts = [{
name: 'inPack',
message: 'Yo dawg, in which pack is your component ? (you can just press enter if it\'s not in a pack)',
default: ''
}]
this.prompt(prompts, function (props) {
this.inPack = props.inPack;
}.bind(this));
done();
}
else
done();
}.bind(this));
the problem is that the 'writing' function is called before the if (whatever the if works), so I'd like to know how to do it properly because i guess this isn't the good way
Well Yeoman is only JavaScript so if you handle the asynchronous order correctly, any if/else statement would work.
That being said, you'd remove all that async overhead if you rely on the when
property of a question. See https://github.com/SBoudrias/Inquirer.js#question