我们可以使用Gulp创建cordova项目的.ipa和.apk吗?

时间:2017-04-12 14:33:24

标签: cordova gulp

有没有办法使用Gulp为Cordova项目创建ipa和apk? 我只想定期运行任务,以便将两个版本保存在给定位置。

2 个答案:

答案 0 :(得分:0)

是的,你可以。看看这个示例脚本(对于android目标):

    var gulp = require("gulp"),
    cordova = require("cordova-lib").cordova;
    gulp.task("default", function (callback) {
        cordova.build({
            "platforms": ["android"],
            "options": {
                argv: ["--release","--gradleArg=--no-daemon"]
            }
        }, callback);
    });

这适用于多平台构建(使用taco team build):

var gulp = require("gulp"),
    fs = require("fs"),
    es = require('event-stream'),
    cordovaBuild = require("taco-team-build");

// Setup platforms to build that are supported on current hardware
var winPlatforms = ["android", "windows"],
    linuxPlatforms = ["android"],
    osxPlatforms = ["ios"],
    platformsToBuild = process.platform === "darwin" ? osxPlatforms :                   
                       (process.platform === "linux" ? linuxPlatforms : winPlatforms),   

    // Build config to use for build - Use Pascal case to match paths set by VS
    buildConfig = "Release",

    // Arguments for build by platform. Warning: Omit the 
    // extra "--" when referencing platform specific options 
    // (Ex:"-- --gradleArg" is "--gradleArg").
    buildArgs = {
        android: ["--" + buildConfig.toLocaleLowerCase(),"--device",
                  "--gradleArg=--no-daemon"],                
        ios: ["--" + buildConfig.toLocaleLowerCase(), "--device"],                                             
        windows: ["--" + buildConfig.toLocaleLowerCase(), "--device"]                                          
    },                                                                              

    // Paths used by build
    paths = {
       apk:["./platforms/android/ant-build/*.apk", 
            "./platforms/android/bin/*.apk", 
            "./platforms/android/build/outputs/apk/*.apk"],
       binApk: "./bin/Android/" + buildConfig,
       ipa: ["./platforms/ios/build/device/*.ipa",
             "./platforms/ios/build/device/*.app.dSYM"],
       binIpa: "./bin/iOS/" + buildConfig,
       appx: "./platforms/windows/AppPackages/**/*",
       binAppx: "./bin/Windows/" + buildConfig
    };                                                  

// Set the default to the build task
gulp.task("default", ["build"]);

// Executes taks specified in winPlatforms, linuxPlatforms, or osxPlatforms based on
// the hardware Gulp is running on which are then placed in platformsToBuild
gulp.task("build", function() {
    return cordovaBuild.buildProject(platformsToBuild, buildArgs)
        .then(function() {    
            // ** NOTE: Package not required in recent versions of Cordova
            return cordovaBuild.packageProject(platformsToBuild)
                .then(function() {             
                    return es.concat(
                            gulp.src(paths.apk).pipe(gulp.dest(paths.binApk)),
                            gulp.src(paths.ipa).pipe(gulp.dest(paths.binIpa)),
                            gulp.src(paths.appx).pipe(gulp.dest(paths.binAppx)));            
                });
        });
});

如果您愿意,也可以使用以下内容:gulp-cordova-build-android

答案 1 :(得分:0)

看看这个插件。 https://github.com/antwerpes/gulp-angular

它包含所有任务的列表,您还可以指定FTP,配置文件等等。

你甚至可以建立基本结构。

基本构建任务 https://github.com/antwerpes/gulp-angular#build