2016-04-22 51 views
0

我有一个Grunt任务来自动化web服务器在web服务器上的部署。 在我的网络服务器我有3种途径:在Grunt任务中建议部署路径

  • /WWW /对myApp(生产)
  • /WWW/myApp_rc

我有一个package.json文件

{ 
... 
    "ftpDeployPath":"myApp_rc" //or /www/myApp 
... 
} 

,这是我的任务

{'ftp-deploy': { 
       toMyServer: { 
        auth: { 
         host: '10.7.88.87', 
         port: 21, 
         authKey: 'key1' 
        }, 

        src: 'deploy', 
        dest: '<%= pkg.ftpDeployPath %>', 
        forceVerbose: true 
       } 
      } 

}

当我想要部署,每次我有时间来检查,最终编辑package.json文件。 是否有任何方式显示提示(bu grunt控制台)以允许我选择正确的部署路径?

回答

1

你可以尝试使用'输入'问题类型的grunt-prompt任务,并将'ftpDeployPath'设置为'config'。或者,修改gruntfile以使用命令行选项(http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks),并从WebStorm(设置|工具|外部工具)作为外部工具运行任务 - 您可以将$ Prompt $宏添加到工具参数中,以在运行时获得选项值提示一个工具

0

使用命令行参数和自定义任务的组合,可以在运行任务之前修改任务的配置。我们首先通过修改dist的模板字符串开始;更改访问grunt.option() PARAM称为deployPath我们的自定义任务将设置:

grunt.initConfig({ 
    'ftp-deploy': { 
     toMyServer: { 
      auth: { 
       host: '10.7.88.87', 
       port: 21, 
       authKey: 'key1' 
      }, 
      src: 'deploy', 
      dest: '<%= grunt.option('deployPath') %>', 
      forceVerbose: true 
     } 
    } 
}); 

接下来,精心创建设置grunt.option('deployPath')参数自定义任务。当您运行grunt deploy:prod时,以下任务将deployPath设置为myApp。如果您只运行grunt deploy,则路径设置为myApp_rc。一旦选择路径,则自定义然后调用ftp-deploy任务:

function deployTask(grunt) { 
    var deployPath = (this.args[0] === 'prod') ? 'myApp' : 'myApp_rc'; 
    grunt.option('deployPath', deployPath); 
    grunt.task.run('ftp-deploy'); 
} 

grunt.registerTask('deploy', deployTask);