Created
September 26, 2016 00:24
-
-
Save matteo-bombelli/f4c8bc17ec83a12cb0de058016aa1f8f to your computer and use it in GitHub Desktop.
Hacky solution: Yeoman generator nested prompt...
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)); | |
}, | |
configuring: function (){ | |
}, | |
promptingSecond:function(){ | |
// this should fall in the default group | |
var props = this.props; | |
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: "" | |
}; | |
} | |
return this.prompt(questions2).then(function(props2){ | |
this.props2 = props2; | |
}.bind(this)); | |
} | |
}, | |
conflicts: function (){ | |
}, | |
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
I've created a "promptingSecond" (line 51) task, that will fall after prompting, cause it will fall in the default group but i don't really like it cause it can be strange if there are nested loops questions like...