May 2015

Gavin Pickin

Post Conference - Session Review - Getting your hooks into Cordova- Workflows and Build Helpers

Android, cfObjective, Cordova / Phonegap, Dev.Objective, Ionic, Javascript, Mobile Development, Node.js, Unit Testing

May 15th, 2015 was the last day of dev.Objective(), and the last session of the day had some great topics, “Devops: journeyman to infrastructure mastery”, ‘Marketing for Developers’, ‘Level Up your Javascript: Understanding the confusing bits’, ‘Web sockets, yes they can do that too', and my session, ‘Getting your Hooks into Cordova - Workflows and Build Helpers'. With mobile and hybrid development really growing into a track of its own, I decided to submit this topic, as I believe Cordova Hooks are a big part of Cordova mobile development, they save me hours every week, and they are relatively unknown if you search for blog posts about them. When the session was accepted, I took that as a challenge to up my game and really research hooks, and make my presentation a complete resource.

I did not expect a big crowd of people, especially with the competition of the other topics, and of course a lot of people leaving early for flights, or saying their last minute goodbyes. We had a small intimate group, which allowed us to have a very open conservation, and I think we all got a lot out of the session.

For those of you who do not know what Cordova hooks are, they are scripts you can run automatically at given points during the development process, at these points, events are triggered and any hook listening for that event will fire For example, every time you build the app for iOS you can fire a hook that inserts a special iOS themed CSS, or anytime you build your app, after build you could run uglificatiom and minimization of your files.

Hooks can be written in bash files, bat files, but it is recommended to use NodeJS since the CLI is written in node, so its obviously platform independent and available.
Having attended the Birds of Feather (BOF) the night before my presentation, I was inspired to write a few new hooks the day of, and that went over really well with everyone.

These are the hooks I showed... and what they do, I intend to post a separate post for each individual hook, and will update this post and the mini site accordingly.

Environment Setup-  before_build
This hook allows you to set an environment variable at the command line, and change the output of the build, depending on if you’re building for dev, staging, or production. This makes it easy to update API urls, api keys, debugging output, and much more.

CordovaCleanup - before_build
This is a simple script that cleans up those annoying operating system files like .DS_Store and Thumbs.db etc. It could be configured to clean up more. This can be configured and extended to suite your development needs.

JS Hint - before_build
This hook has a list of directories I want the build process to lint with JS Hint. This step hints all my code and exits if it finds errors, giving me all the info I need to fix it, before building again.

Jasmine Unit Tests- before_build
After my JS Hint hook has fired, and succeeded, then my Unit Tests run with Jasmine. If the unit tests all pass, the build continues, otherwise the process ends. Success or failure, Jasmine outputs number of specs, execution time etc.

JSON - before_build
This hook runs before build, and hits web service for a Json response, and stores the file in your app, so when packaged, your app has a semi recent set of data to come preloaded, without the need of a full sync.

Uglify - after_build
This hook runs after the build and uglifies and minifies the files in the location specified.

My presentation mini site is available here on my blog at

As I add more blog posts about this topic, I will continue to update the mini site.
The minisite has links to the gists of all the hooks I had, the slided and links to the few blog posts I did find on the topic.

I really think hat Cordova hooks are awesome, if you are a Cordova developer, or Ionic developer (Ionic cli is built on top of Cordova), give them a try.
If you are using them, please share some of the hooks you are using.

Thanks for reading.

Blog Search