Skip to content

Instantly share code, notes, and snippets.

@matteo-bombelli
Last active September 26, 2016 00:24
Show Gist options
  • Save matteo-bombelli/83ce4d7f03053cf1aed6b7480df99b31 to your computer and use it in GitHub Desktop.
Save matteo-bombelli/83ce4d7f03053cf1aed6b7480df99b31 to your computer and use it in GitHub Desktop.
Yeoman generator nested prompt not working...
'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;
}
});
@matteo-bombelli
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment