gruntjs / grunt-init

Generate project scaffolding from a template.
http://gruntjs.com/project-scaffolding
MIT License
193 stars 58 forks source link

Ability to skip a prompt #73

Open gamtiq opened 10 years ago

gamtiq commented 10 years ago

IMHO one of important features that grunt-init lacks is ability to skip a question (prompt) depending on answers for previous questions (results of previous prompts). For example, consider the following excerpt (actually it is prompts from grunt-init-pack template):

{
    name: "travis",
    message: "Will this project be tested with Travis CI?",
    "default": "Y/n",
    warning: "If selected, you must enable Travis support for this project in https://travis-ci.org/profile",
    sanitize: convertYesNo
},
{
    name: "travis_badge",
    message: "Would you like to include Travis build status badge into README.md?",
    "default": function(value, data, done) {
        done(null, yesRegExp.test(data.travis) ? "Y/n" : "y/N");
    },
    sanitize: convertYesNo
},

When a user answers no for travis prompt, travis_badge prompt should be skipped. Unfortunately it is impossible in current version.

I propose to add support for prompt's options that will allow specifying pre-action and maybe post-action (of course they should be functions). Let’s name those actions before and after. So that when false value (exactly) is returned from before action, the corresponding prompt will be skipped. What do you think about this? I can make pull request if this proposal will be approved.