Skip to content

Instantly share code, notes, and snippets.

Last active October 11, 2015 12:37
What would you like to do?
Shell script to update 3rd party libs
# This shell script is used to bootstrap the app and update external libraries
# ====== IMPORTANT ======
# it may break application if 3rd party libs aren't backwards compatible
# or if libs were edited locally, use with care !!!
# Settings ----------
# if $IS_SVN is `true` it will avoid deleting ".svn" folders
# set to `false` if using Git/Mercurial or SVN 1.7+
# if $IS_HANDLEBARS it will download RequireJS handlebars plugin if not it
# downloads the hogan plugin
if [ ! -d "$JS_FOLDER" ]; then
mkdir -p "$JS_FOLDER/lib/jquery/"
mkdir -p "$JS_FOLDER/lib/require/"
if [ ! -d "$CSS_FOLDER" ]; then
mkdir -p "$CSS_FOLDER"
# Update ----------
echo "\n == UPDATING LIBS =="
echo "\n -- updating jquery.js --\n"
curl > "$JS_FOLDER/lib/jquery/jquery.js"
echo "\n -- updating signals.js --\n"
curl > "$JS_FOLDER/lib/signals.js"
echo "\n -- updating crossroads.js --\n"
curl > "$JS_FOLDER/lib/crossroads.js"
# RequireJS ----------
echo "\n -- updating require.js --\n"
curl > "$JS_FOLDER/lib/require/require.js"
echo "\n -- updating require/text.js --\n"
curl > "$JS_FOLDER/lib/require/text.js"
echo "\n -- updating require/async.js --\n"
curl > "$JS_FOLDER/lib/require/async.js"
echo "\n -- updating require/json.js --\n"
curl > "$JS_FOLDER/lib/require/json.js"
echo "\n -- updating require/image.js --\n"
curl > "$JS_FOLDER/lib/require/image.js"
echo "\n -- updating require/mdown.js --\n"
curl > "$JS_FOLDER/lib/require/mdown.js"
curl > "$JS_FOLDER/lib/require/Markdown.Converter.js"
echo "\n -- updating require/hbs.js --\n"
curl > "$JS_FOLDER/lib/require/hbs.js"
curl > "$JS_FOLDER/lib/Handlebars.js"
if [ ! -d "$JS_FOLDER/lib/require/hbs" ]; then
mkdir "$JS_FOLDER/lib/require/hbs"
curl > "$JS_FOLDER/lib/require/hbs/i18nprecompile.js"
curl > "$JS_FOLDER/lib/require/hbs/json2.js"
curl > "$JS_FOLDER/lib/require/hbs/underscore.js"
echo "\n -- updating require/hgn.js --\n"
curl > "$JS_FOLDER/lib/require/hgn.js"
curl > "$JS_FOLDER/lib/hogan.js"
# text plugin is a dependency
curl > "$JS_FOLDER/lib/require/text.js"
# Other Libs -----------
echo "\n -- updating moutjs --\n"
if $IS_SVN; then
find "$JS_FOLDER/lib/mout" ! -wholename '*.svn*' -type f -delete
rm -rf "$JS_FOLDER/lib/mout"
git clone --depth 1 "$SWAP_FOLDER/mout"
cp -R "$SWAP_FOLDER/mout/src/." "$JS_FOLDER/lib/mout/"
mv "$SWAP_FOLDER/mout/" "$JS_FOLDER/lib/mout/"
echo "\n -- updating MM_js_lib --\n"
if $IS_SVN; then
find "$JS_FOLDER/lib/millermedeiros" ! -wholename '*.svn*' -type f -delete
rm -rf "$JS_FOLDER/lib/millermedeiros"
git clone --depth 1 "$SWAP_FOLDER/millermedeiros"
cp -R "$SWAP_FOLDER/millermedeiros/src/." "$JS_FOLDER/lib/millermedeiros/"
mv "$SWAP_FOLDER/millermedeiros/README.markdown" "$JS_FOLDER/lib/millermedeiros/"
echo "\n -- updating basis.css --\n"
if $IS_SVN; then
find "$CSS_FOLDER/bss" ! -wholename '*.svn*' -type f -delete
rm -rf "$CSS_FOLDER/bss"
git clone --depth 1 "$SWAP_FOLDER/basis"
if $START_CSS; then
cp -R "$SWAP_FOLDER/basis/css/." "$CSS_FOLDER"
# we update only the "bss" folder otherwise it might overwrite user styles
cp -R "$SWAP_FOLDER/basis/css/bss/." "$CSS_FOLDER/bss/"
mv "$SWAP_FOLDER/basis/" "$CSS_FOLDER/bss/"
# Finish -----------
echo "\n -- clean swap folder --\n"
rm -rf "$SWAP_FOLDER"
echo "\n == FINISHED UPDATE == \n"
Copy link

I've been using shell scripts similar to this for the past couple years to install/update 3rd party libs. I usually keep the whole code commented out and just enable the parts that I want to run that way I avoid updating the wrong libs.

This could be replaced by a package manager like:

But I kinda like the "simplicity" of the shell script specially since most of my dependencies are solved with simple curl calls and I don't execute this script that often.

Copy link

Another thing that is good to note is that I ALWAYS keep the dependencies on my version control system so future devs don't need to execute this script. - I rarely update libs after deploy (only for bug fixes).

Package managers are great and solve lots of problems (resolving dependencies, downloading proper files, etc..) but I still haven't found a client side package manager that fits my desires/needs. I like to organize my files on a very specific way and I don't like a lot of "garbage" inside the 3rd party libraries folder (git clone isn't enough). I also like to use the unminified version of the scripts during development so I can fix things if needed and have proper line diffs in case I update the lib to a newer version or change the code myself.

Package management for the client-side is a very complex "problem" that might not be solved in the near future, specially since we have so many different kinds of dependencies (images, css, fonts, js) and so many different project structures (AMD, CJS, multiple script tags, namespaces, globals, etc). There is no easy way to sandbox each component so we can have multiple versions running simultaneously without conflicts (solving this in JS is easier than CSS) and we probably won't agree about the best format anytime soon...

Since it takes me less than 15min to create a script like this for each project, and it works for my own needs, I don't think I will invest my time trying to come up with yet-another-client-side-package-manager.

Copy link

Interesting thoughts on client-side package managers. Thanks for posting this up here!

Copy link

Always use double quotes. Please add some.

Especially stuff like:

rm -rf $JS_FOLDER/lib/mout

…is potentially dangerous. (What if $JS_FOLDER contains a space?)

Copy link

I started using Bower for a project, but I didn't like to download the entire repository (docs, tests, README etc), I just wanted the minified and unminified version of the lib.

Maybe this behaviour happened because the lib didn't implement the "component.json" properly, but event if it did, as far as I know, the "component.json" only allow to specify 1 "js" file to be "downloaded".

Copy link

update: I’ve been using more often instead of the ad-hoc shell scripts, it's flexible enough and let me do basically the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment