grunt-init template conditional prompts

混江龙づ霸主 提交于 2020-01-14 03:31:07

问题


I'm creating a new grunt-init template for my project and was wondering if there is a way to do conditional prompts based on the answers given to previous prompts.

My main goal is to be able to use the Github API to create an issue when I create a new module in my project. After asking for the module information, I would ask if a Github issue should be created. If yes, then ask for information like assignee, milestone, labels. If no, I don't care about any of those features.

Right now, I can just default them to blanks, but I'd like to just skip those prompts entirely.


回答1:


The init property exposes a init.prompts() object which you could modify based on the answers.

Something like this:

exports.template = function(grunt, init, done) {
    init.process([
        init.prompt('create_github_issue', function(value, props, done) {
            init.prompts['milestone'] = init.prompt('milestone');
            done();
        })
    ], function(err, props) {
        // handle all the props
        done();
    });
};

See the gruntplugin template for how to implement an init task.



来源:https://stackoverflow.com/questions/14150251/grunt-init-template-conditional-prompts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!