私のジェネレータコードは次のとおりです。私はそれを実行するときにいくつかの面白い振る舞いを見ている。一度それがの第二を尋ねると、それもwriting
の下の呼び出しコード。一度プロンプトが完了した後に実行する必要はありません?私は間違って何をしていますか?yeomanジェネレータはプロンプトを表示してループを実行します
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
};