Chapter 1. Task Automation
While developing your app, there are often many tasks that need to be executed on a recurring basis. Although these tasks are rarely difficult or terribly time-consuming, over time, the effort adds up and it quickly becomes tiresome and error-prone.
Task automation simplifies these tiresome rituals. Automation lets you define the steps for tasks that you frequently execute (and even those that you execute infrequently, which may be even more useful). In a way, you could consider task automation similar to macros in other productivity applications you might use (such as Microsoft Word).
Inpidual tasks can also depend on other tasks, so you can simplify your manual processes to one or two easy-to-remember and easy-to-type commands. Furthermore, most task automation utilities provide a mechanism to watch for changes made to your project, automatically executing various tasks when any changes have been detected.
Technically, task automation isn't required while developing a PhoneGap / Cordova app; but as your apps grow larger and more complex, it becomes increasingly beneficial. There is some initial overhead, of course, which is often why small projects never implement task automation. But when an app has several views, lots of modules, and a good number of dependencies, the initial overhead quickly pays off.
Note
Although this book is titled Mastering PhoneGap Mobile Application Development, we will be using Cordova to refer to PhoneGap and Cordova. PhoneGap is derived from Cordova and everything we do using Cordova will also work with PhoneGap. Where this doesn't hold true, we'll mention it explicitly.
Also, when we're referring to Cordova and PhoneGap, we are referring to the command-line utilities. There is a PhoneGap Build service available that performs compilation and packaging in the cloud; but if you want to use it, you'll need to adapt the content in this book appropriately. If you want to learn more, see the README.md
file in the code package for this book.
There are several different task automation utilities available. Because one generally writes the majority of their Cordova app in HTML, CSS, and JavaScript, it makes sense to select a task automation system based on JavaScript. At the time of this writing, Gulp (http://gulpjs.com) and Grunt (http://gruntjs.com) are the most popular of the various available utilities.
In this chapter, you will learn about:
- Logology, the demonstration app
- Why use Gulp for Task Automation
- Setting up your app's directory structure
- Installing Gulp
- Creating your first Gulp configuration file
- Creating a modular Gulp configuration
- Copying assets
- Performing substitutions
- Executing various Cordova tasks
- Managing version numbers
- Supporting ES2015
- Linting your code
- Minifying/uglifying your code