Automating PhoneGap Builds with Gulp. Part I

 
event

Lately, my team has been doing some hybrid mobile apps development with Cordova and Ionic and one of the multiple challenges faced during such development is:

how (and where) do I build the resulting app?

Local vs. Semi-local vs. Remote

Of course, we can follow Cordova’s guides and build the application locally. That is probably the fastest:

  • time of setting-up, as it is well documented
  • performance-wise, since developers tend to use powerful machines themselves
  • time-to-device: connect you phone and push the resulting app through cable @

It has a pretty serious drawback: forget about building iOS apps unless you have a Mac and… most of us do not have one, some of us do not want one as a work machine and do not fancy the idea of switching machines/OSs back and forth and using that crazy keyboard layout.

Semi-local refers to the new old idea of having a build machine (a Mac in our case) that can build the apps for all the platforms. It something that other teams that develop hybrid apps have done in our company and works for them. Unfortunately, after spending pretty much 5 days fighting tools that we are not familiar with (Grunt, Gulp, Jenkins, Android and iOS SDKs) we were still nowhere near the automation Nirvana.

There is Remote left. And by remote I refer to the ability of someone else building your app off-premises. A 15 minutes walk-through and we got our app built for all supported platforms. That’s all it took to PhoneGap Build (PGB) to be chosen.

Money talks

Their free tier allows a single private app (one which GitHub repository cannot be accessed publicly) and restricts the app size and the ability to upload plugins.

And none of that disturbs our app, so free it is.

The Objective

What we wanted to achieve with our build and deployment scripts is simple: from the command line (the closest to one-button I want to get), generate the artifacts needed to compile the app for a given environment (development, staging or production), queue a build that compiles the application for all supported platforms and automate the deployment to our distribution platform.

The foundation

Before deciding how to automate the build, we were already using Gulp to “compile” the front-end (Sass to CSS, bundle and serve the static website), so we saw no reason for not using it for all automation.