Last active
November 5, 2019 20:21
-
-
Save vyuvalv/4894da801d686a39de66b8dd0fe39bbf to your computer and use it in GitHub Desktop.
Prompt Questions with Validate and Conditional Render questions
This file contains hidden or 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
prompting() { | |
// asking questions | |
const questions = [ | |
{ | |
type: 'checkbox', | |
name: 'mainMenu', | |
message: 'What would you like to do ?', | |
validate: function(choices) { | |
return choices.length > 0 ? true : chalk.redBright('Must Select at least one option'); | |
}, | |
choices: [ | |
{ | |
type: 'separator', | |
line:'-˯-˯-˯-˯-˯-˯-˯' | |
}, | |
{ | |
name: 'New Project', | |
value: 'create-project' , | |
checked: false | |
}, | |
{ | |
name: 'New Scratch Org', | |
value: 'create-org', | |
checked: false | |
}, | |
{ | |
name: '🍣 Manage DX', | |
value: 'manage-dx', | |
checked: false | |
}, | |
{ | |
name: '🥡 Open Project Folder', | |
value: 'open-project' , | |
checked: false | |
}, | |
{ | |
type: 'separator', | |
line: '-^-^-^-^-^-^-^' | |
}, | |
{ | |
name: chalk.inverse('Exit'), | |
value: 'exit', | |
checked: false | |
}, | |
{ | |
type: 'separator', | |
line: '-^-^-^-^-^-^-^' | |
} | |
] | |
}, | |
{ | |
type : 'confirm', | |
name : 'useDefaultOrgs', | |
message : 'Use Default Orgs ?', | |
default : true, | |
when: function(answers) { | |
return answers.mainMenu.includes('manage-dx') ? true : false; | |
} | |
} | |
]; | |
return this.prompt(questions).then(answers => { | |
this.log("========================="); | |
// asign all answers to this.props | |
this.props = answers; | |
// call inputs from this.props[name] | |
this.log("========================="); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment