CLOSE ×
Get in Touch
Thank you for your interest! Please fill out the form below, and I will do my best to get back to you.

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form.

JavaScript Library Nightly Builds, SymLinks and Auto-Updates

Garth Henson
|
JavaScript
|
19 Nov 2009

Something has been bothering me for some time, and I finally took the time to resolve the issue once and for all – relatively speaking. As mentioned in my previous post, I have had opportunity to work with multiple different JavaScript libraries, and I often find myself running behind on the newest bug fixes for a given module. Many of the library development teams offer a nightly build available to checkout via SVN or Git (usually by way of GitHub), and I devised a way to automatically update my shared repositories among all the domains on my server. While not rocket science, nor an entirely new idea to most of you, it is quite helpful to me, and I thought I’d share my method here.

There are actually four steps involved with this update, so I apologize in advance if this gets too long.

First, we need to set a location for our checkouts. In my case, I just created a “3rdparty” directory off of home. Within that, I started checking out the various repos – for the sake of this post, we’ll follow jQuery from start to finish, since it has the extra step of building as well. Once you have determined the path to which you are going to check out your repos, we create the directory and start importing:

At this point, you have a working checkout of the trunk for jQuery. If you have spent any time perusing the documentation, you may know that this also requires a quick build of the actual jQuery usable files. So, to do that, we also need to navigate into the trunk/jquery directory and execute a make command:

Now that we have checked out and built our working repository, we are ready to symlink the resulting dist directory to any domains that need access to the updated code base. To do so, simply navigate to the domain of choice, determine an accessible location and link the files. In my case, I chose to place all 3rdparty libraries available within a /scripts/3rdparty/ directory underneath my domain’s web root:

At this point, you should be able to include either the full jquery.js or jquery.min.js by simply referencing this symlink from within any HTML document within this domain:

So far, this has been pretty standard practice if you’ve done anything with sharing client side libraries before. Now is where we get into the automated updates. Since I have multiple libraries that use different version control software packages, I decided to write a very simple PHP script that allows me to easily define a path and a versioning system from the command line and automatically update that repository. Without getting into a line-by-line of the script, here is the code for it (created as $HOME/scripts/lib_updater.php):

With this script in place, we can automate the update of any given library by providing the -t and -p parameters to our script. So, the following line of code will update our jQuery checkout:

As it is, this script will run the update command on any directory that is a checkout from SVN, CVS or GIT. This covers all major JavaScript libraries available (at least the ones I am using).

Finally, we will apply the remote update script to a crontab to automate the actual execution of the script. In my case, though jQuery offers a nightly build, I really only care to pull once each week, so I set up the following job with a call to crontab -e. Remember that jQuery requires a build for the new changes to take effect, so we will have two entries – one for the update and one for the build. I run them every Monday morning at midnight and 1am respectively:

When the cron is installed, you will start having your jQuery core be updated from the latest nightly release and built every Monday morning. In addition, since we have symbolic links to each domain that needs the newest jQuery, as soon as our update is built, the resulting files are already being referenced by our domains. By doing so, we can assure that the newest bug fixes or feature releases are always available to our users.

Of course, doing automation like this across major development releases of a library would be foolish due to deprecated methods and features, but within a major build, minor releases are usually quite safe. If instead, you wish to pull from a specific tag rather than trunk, most of the libraries also allow you to select a specific branch or tag from which to pull. A minor update to the PHP script here would also allow you to manually override the branch being pulled as well.

Once you have the pattern in place, the possibilities are endless.

Garth Henson
Garth is as a lead engineer at The Walt Disney Company, specializing in JavaScript applications.

Recent Blog Posts

Let's Work Together
Contact Me