I have my generator code like the following. I'm seeing some funny behavior when i run it. Once it ask the second Add property...
, its also calling code under writing
. Isn't supposed to run once prompting has completed? What am I doing wrong?
app/index.js
'use strict'
var generators = require('yeoman-generator');
var questions = require('./questions');
module.exports = generators.Base.extend({
constructor: function () {
generators.Base.apply(this, arguments);
this.argument('name', { type: String, required: true });
},
initializing: function () {
this.properties = [];
},
prompting: {
askForProperties: questions.askForProperties
},
writing: function(){
this.log("brewing your domain project");
}
});
app/questions.js
'use strict'
var chalk = require('chalk');
function askForProperties() {
var prompts = [
{
type: 'confirm',
name: 'addProp',
message: 'Add property to your model (just hit enter for YES)?',
default: true
},
{
type: 'input',
name: 'propName',
message: 'Give name to your property?',
when: function (response) {
return response.addProp;
}
},
{
type: 'list',
name: 'propType',
message: 'Pick a type for your property',
choices: [
{
value: 'string',
name: 'string',
},
{
value: 'int',
name: 'int'
},
{
value: 'bool',
name: 'bool'
},
{
value: 'decimal',
name: 'decimal'
}],
default: 0,
when: function (response) {
return response.addProp;
}
}
];
return this.prompt(prompts).then(function (answers) {
var property = {
propertyName: answers.propName,
propertyType: answers.propType
};
this.properties.push(answers.propName);
if (answers.addProp) {
askForProperties.call(this);
}
}.bind(this));
}
module.exports = {
askForProperties
};