I have written a Yeoman sub generator and I want to access the answers acquired from the prompts in the main (parent) generator. The format to access the answers in the main generator's index.js file is this.promptName
. Is it possible to retrieve those answers within the sub generator?
This is what I currently have but (obviously) doesn't work:
var ComponentGenerator = yeoman.generators.NamedBase.extend({
init: function () {
if (this.wordpress) { // this.wordpress set from main generator
console.log('is wp');
} else {
console.log('not wp');
}
}
});
module.exports = ComponentGenerator;
You need to pass them as options to the sub generator:
this.composeWith('subgenerator', {options: {name: 'some-name'}});
Then in your sub generator:
this.option('name', {/* settings */});
See the full documentation here: