2014-03-29 49 views
0

我正在使用這裏找到的grunt-git插件:https://github.com/rubenv/grunt-git。該插件定義了一些任務,例如gitpush和gitpull等等。以下是gitpush任務的示例:如何用不同的選項/參數使用相同的grunt任務?

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

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

分支選項是必需的。它的默認值爲null,即我可以將它留空,因爲它不會推送到我所在的當前分支,它根本就不會推送。有時我想用它來推送到「主」分支,而不是「cojo」分支。我無法弄清楚的是(我是Grunt的新手)是如何使用不同的名稱再次創建gitpush任務,以便讓它可以選擇推送到主服務器。在我的腦子裏,我想象我想是這樣的:

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

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

這顯然還不是因爲gitpush是繁重的,git的插件定義的任務名稱的工作。我想到的另一個選擇是創建別名任務並將參數傳遞給它,但我不知道這是否可行。

回答

2

使用不同的目標。

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

使用gitpush:cojo或gitpush:master根據需要運行這些。

相關問題