Last active
September 26, 2016 00:24
-
-
Save matteo-bombelli/83ce4d7f03053cf1aed6b7480df99b31 to your computer and use it in GitHub Desktop.
Yeoman generator nested prompt not working...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var yeoman = require('yeoman-generator'); | |
var chalk = require('chalk'); | |
var yosay = require('yosay'); | |
module.exports = yeoman.Base.extend({ | |
prompting: function () { | |
// Have Yeoman greet the user. | |
this.log(yosay( | |
'Welcome to the amazing ' + chalk.red('generator-try-mb') + ' generator!' | |
)); | |
var prompts = [{ | |
type: 'checkbox', | |
name: 'someAnswer', | |
message: 'select languages', | |
choices: ["en","it","de","fr","es","pt","ru"], | |
default: [] | |
}]; | |
var questionary = this; | |
return this.prompt(prompts).then(function (props) { | |
// To access props later use this.props.someAnswer; | |
if(props.someAnswer.length>0){ | |
var questions2=[]; | |
var i=0; | |
for(i=0; i<props.someAnswer.length; i++){ | |
questions2[i] = { | |
type:'input', | |
name:'two'+props.someAnswer[i], | |
message:'translation of "this thing" in '+props.someAnswer[i], | |
default: "" | |
}; | |
} | |
this.prompt(questions2).then(function(props2){ | |
this.props2=props2; | |
}.bind(this)); | |
} | |
this.props = props; | |
}.bind(this)); | |
}, | |
writing: function () { | |
this.log(JSON.stringify(this.props)); | |
this.log(JSON.stringify(this.props2)); | |
this.fs.copy( | |
this.templatePath('dummyfile.txt'), | |
this.destinationPath('dummyfile.txt') | |
); | |
}, | |
install: function () { | |
// this.installDependencies(); | |
}, | |
end: function(){ | |
this.log(" bye! "); | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hacky solution: https://gist.github.com/matteo-bombelli/f4c8bc17ec83a12cb0de058016aa1f8f