Friday 6 September 2013

Using Grunt-phonegap-build: depricating grunt-zipstream and buiding on other platforms

If you use Grunt and want to automate builds in build.phonegap.com you may have noticed the Grunt-Phonegap-Build plugin. However the documentation is a little bit outdated. For one, Grunt-zipstream doesn't work with newer versions of Node.js (as of the writing here), so we will substitute in Grunt-contrib-compress. Then there is the fact that iOS uses certs now, and there is a key/password example in the documentation? It turns out that you can simply omit this line and build with iOS no problem! Finally there are the missing examples for Blackberry and Windows Phones builds. Yes, you can do them, and I will show you how:

Replacing Grunt-zipstream

We will use Grunt-contrib-compress instead with the following configuration:
var compressConfig = {
        main: {
            options: {
                archive: 'app.zip'
            },
            expand: true,
            src: ['*.html', 'styles/**/*.css', 'srcipts/**/*.js', 'favicon.ico', 'images/**/*'],
        }
    };
and with a sub-directory using a variable for Yeoman
var compressConfig = {
        main: {
            options: {
                archive: 'app.zip'
            },
            expand: true,
            cwd: '<%= yeoman.app %>/',
            src: ['*.html', 'styles/**/*.css', 'srcipts/**/*.js', 'favicon.ico', 'images/**/*'],
        }
    };
 You can replace "zip" with "compress" in the documentation, or make a separate task like I did:
grunt.registerTask('remote_build', [
        'compress',
        'phonegap-build:debug'
    ]);

Blackberry and Windows Phone builds

Wondering how to make Windows Phone Builds with Grunt-phonegap-build? To build out for iOS, Android, Blackberry, and Windows Phone you can do your setup this way:

var phonegapBuildConfig = {
        debug: {
            options: {
                archive: 'app.zip',
                'appId': 'XXXXXX',
                'user': {
                    'email': 'myemail@server.com',
                    'password': 'password1234'
                },
                keys: {
                    //ios: { 'password': password1234' },
                    android: { 'key_pw': 'password1234', 'keystore_pw': 'password1234' },
                    blackberry: { 'password': 'password1234'}
                },
                download: {
                    ios: 'dist/ios.ipa',
                    android: 'dist/android.apk',
                    blackberry: 'dist/blackberry.ota',
                    winphone: 'dist/winphone.xap'
                }
            }
        }

};

No need for the iOS password anymore, see how to specify the key for Blackberry, and the attribute name for Windows Phone is "winphone"!

Here is everything in total:
module.exports = function (grunt) {
    // show elapsed time at the end
    require('time-grunt')(grunt);
    // load all grunt tasks
    require('load-grunt-tasks')(grunt);

    //REMOTE (build.phonegap.com) phonegap (for devices) builds
    grunt.loadNpmTasks('grunt-contrib-compress');
    grunt.loadNpmTasks('grunt-phonegap-build');

    // configurable paths
    var yeomanConfig = {
        app: 'app',
        dist: 'dist'
    };

    var phonegapBuildConfig = {
        debug: {
            options: {
                archive: 'app.zip',
                'appId': 'XXXXXX',
                'user': {
                    'email': 'myemail@server.com',
                    'password': 'password1234'
                },
                keys: {
                    //ios: { 'password': password1234' },
                    android: { 'key_pw': 'password1234', 'keystore_pw': 'password1234' },
                    blackberry: { 'password': 'password1234'}
                },
                download: {
                    ios: 'dist/ios.ipa',
                    android: 'dist/android.apk',
                    blackberry: 'dist/blackberry.ota',
                    winphone: 'dist/winphone.xap'
                }
            }
        };

    var compressConfig = {
        main: {
            options: {
                archive: 'app.zip'
            },
            expand: true,
            cwd: '<%= yeoman.app %>/',
            src: ['*.html', 'styles/**/*.css', 'srcipts/**/*.js', 'favicon.ico', 'images/**/*'],
        }
    };

    grunt.initConfig({
        'phonegap-build': phonegapBuildConfig,
        compress: compressConfig
    });

    grunt.registerTask('remote_build', [
        'compress',
        'phonegap-build:debug'
    ]);
};

Registration (key) pages for various version of Visual Studio Express


If you are looking for the link to a version of Visual Studio Express Registration, here is what I have found so far:

Microsoft® Visual Web Developer® 2008  Express Edition: https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?fu=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2fvsreg%2fdefault.aspx%3frel%3dvs2008%26h%3dd9eac95a73d80105%26pid%3d91911-152-0000077-60782%26bn%3d030729.01%26r%3dy%26lcid%3d1033&wizid=bbcd9486-83de-4770-9541-708db0f37792&lcid=1033

Microsoft® Visual Web Developer® 2010  Express: https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?wizid=345281f9-6588-4888-820f-2695af056d4f

Visual Studio Express 2012 for Web: https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?wizid=C7497E1F-ADA8-4302-9B50-B01855369B2A

Visual Studio Express 2012 for Windows Desktop: https://profile.microsoft.com/RegSysProfileCenter/wizard.aspx?wizid=2525f0ba-d85f-4730-bd75-e1299f83e666&lcid=1033

Hope it helps!