如何以编程方式运行grunt任务nodejs?

时间:2016-03-23 12:10:32

标签: node.js gruntjs sails.js grunt-cli

我需要使用grunt-phonegap-build,我已经以编程方式使用了这个方法:

grunt.loadNpmTasks('grunt-phonegap-build');  
  grunt.initConfig({
                "phonegap-build": {
                        debug: {
                              options: {
                                    archive:"myapp.zip",
                                   "appId":"567576",
                                   "user": {
                                        "email":******,
                                        "password":******
                                        },
                                    download:'dist/android.apk'         
                               }
                         }
                  }
                });
  grunt.tasks('phonegap-build', {}, function(args) {
     grunt.log.ok('Done running tasks.');
  });

问题是执行重复相同的过程以及完成运行任务后#34;。有时它会执行一次。当我按下按钮时,通过ajax调用此功能。我不知道,你可以解释一下吗?怎么解决这个问题?

终端流程:

  Running "phonegap-build:debug" (phonegap-build) task
>> Starting upload
>> Upload successful (HTTP 200)
>> Checking build status successful (HTTP 200)
>> Getting download location for ios successful (HTTP 302)
>> Downloading ios app
>> Checking build status successful (HTTP 200)
>> Checking build status successful (HTTP 200)
>> Downloaded ios app

Running "phonegap-build:debug" (phonegap-build) task
>> Starting upload
>> Checking build status successful (HTTP 200)
>> Checking build status successful (HTTP 200)
>> Upload successful (HTTP 200)
>> Checking build status successful (HTTP 200)
>> Getting download location for ios successful (HTTP 302)
>> Downloading android app
>> Checking build status successful (HTTP 200)
>> Checking build status successful (HTTP 200)
>> Downloaded android app

Done, without errors.
如果我在CLI中给出grunt phonegap-build命令,请手动

。它工作正常。你可以帮帮我吗?

  

以编程方式执行grunt无法正常工作

1 个答案:

答案 0 :(得分:0)

请先创建默认任务,然后调用自定义phonegap任务。

如果你这样做,我没有发布你的完整grunt文件,所以我可以在这里运行它