如何使用不同的选项/参数使用相同的grunt任务?

时间:2014-03-29 03:17:50

标签: git gruntjs

我正在使用此处找到的grunt-git插件:https://github.com/rubenv/grunt-git。该插件定义了一些任务,如gitpush和gitpull等。以下是gitpush任务的一个示例:

 grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    //grunt-git tasks 
    gitpush: {
        task: {
          options: {
              remote: 'origin',
              branch: 'cojo',
        }
      }
    },

分支选项是必需的。它的默认值为null,即我可以将其留空,因为它不会推送到我所在的当前分支,它根本就不会推送。有时候我想用它来推送“master”分支而不是“cojo”分支。我无法弄清楚(我是Grunt的新手)是如何以不同的名称再次创建gitpush任务,以便为其提供推送到主人的选项。在我脑海中,我想象我想要的东西:

 gitpush: {
        task: {
          options: {
              remote: 'origin',
              branch: 'cojo',
        }
      }
    },

 gitpush2: {
        task: {
          options: {
              remote: 'origin',
              branch: 'master',
        }
      }
    },

这显然不起作用,因为gitpush是grunt-git插件定义的任务的名称。我想到的另一个选择是创建别名任务并将参数传递给它,但我不知道这是否可行。

1 个答案:

答案 0 :(得分:2)

使用不同的目标。

gitpush: {
  cojo: {
    options: {
      remote: 'origin',
      branch: 'cojo',
    }
  },
  master: {
    options: {
      remote: 'origin',
      branch: 'master',
    }
  }
}

根据需要使用gitpush:cojo或gitpush:master运行这些。