Skip to content

Instantly share code, notes, and snippets.

@millermedeiros
Last active October 11, 2015 12:37
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save millermedeiros/3859714 to your computer and use it in GitHub Desktop.
Save millermedeiros/3859714 to your computer and use it in GitHub Desktop.
Shell script to update 3rd party libs
#!/bin/sh
# 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 ----------
SWAP_FOLDER="_update_swap"
BASE_FOLDER="."
JS_FOLDER="$BASE_FOLDER/js"
CSS_FOLDER="$BASE_FOLDER/css"
# if $IS_SVN is `true` it will avoid deleting ".svn" folders
# set to `false` if using Git/Mercurial or SVN 1.7+
IS_SVN=false
# if $IS_HANDLEBARS it will download RequireJS handlebars plugin if not it
# downloads the hogan plugin
IS_HANDLEBARS=true
if [ ! -d "$JS_FOLDER" ]; then
mkdir -p "$JS_FOLDER/lib/jquery/"
mkdir -p "$JS_FOLDER/lib/require/"
fi
if [ ! -d "$CSS_FOLDER" ]; then
mkdir -p "$CSS_FOLDER"
START_CSS=true
fi
# Update ----------
echo "\n == UPDATING LIBS =="
echo "\n -- updating jquery.js --\n"
curl http://code.jquery.com/jquery.js > "$JS_FOLDER/lib/jquery/jquery.js"
echo "\n -- updating signals.js --\n"
curl https://raw.github.com/millermedeiros/js-signals/master/dist/signals.js > "$JS_FOLDER/lib/signals.js"
echo "\n -- updating crossroads.js --\n"
curl https://raw.github.com/millermedeiros/crossroads.js/master/dist/crossroads.js > "$JS_FOLDER/lib/crossroads.js"
# RequireJS ----------
echo "\n -- updating require.js --\n"
curl https://raw.github.com/jrburke/requirejs/master/require.js > "$JS_FOLDER/lib/require/require.js"
echo "\n -- updating require/text.js --\n"
curl https://raw.github.com/requirejs/text/master/text.js > "$JS_FOLDER/lib/require/text.js"
echo "\n -- updating require/async.js --\n"
curl https://raw.github.com/millermedeiros/requirejs-plugins/master/src/async.js > "$JS_FOLDER/lib/require/async.js"
echo "\n -- updating require/json.js --\n"
curl https://raw.github.com/millermedeiros/requirejs-plugins/master/src/json.js > "$JS_FOLDER/lib/require/json.js"
echo "\n -- updating require/image.js --\n"
curl https://raw.github.com/millermedeiros/requirejs-plugins/master/src/image.js > "$JS_FOLDER/lib/require/image.js"
echo "\n -- updating require/mdown.js --\n"
curl https://raw.github.com/millermedeiros/requirejs-plugins/master/src/mdown.js > "$JS_FOLDER/lib/require/mdown.js"
curl https://raw.github.com/millermedeiros/requirejs-plugins/master/lib/Markdown.Converter.js > "$JS_FOLDER/lib/require/Markdown.Converter.js"
if $IS_HANDLEBARS; then
echo "\n -- updating require/hbs.js --\n"
curl https://raw.github.com/SlexAxton/require-handlebars-plugin/master/hbs.js > "$JS_FOLDER/lib/require/hbs.js"
curl https://raw.github.com/SlexAxton/require-handlebars-plugin/master/Handlebars.js > "$JS_FOLDER/lib/Handlebars.js"
if [ ! -d "$JS_FOLDER/lib/require/hbs" ]; then
mkdir "$JS_FOLDER/lib/require/hbs"
fi
curl https://raw.github.com/SlexAxton/require-handlebars-plugin/master/hbs/i18nprecompile.js > "$JS_FOLDER/lib/require/hbs/i18nprecompile.js"
curl https://raw.github.com/SlexAxton/require-handlebars-plugin/master/hbs/json2.js > "$JS_FOLDER/lib/require/hbs/json2.js"
curl https://raw.github.com/SlexAxton/require-handlebars-plugin/master/hbs/underscore.js > "$JS_FOLDER/lib/require/hbs/underscore.js"
else
echo "\n -- updating require/hgn.js --\n"
curl https://raw.github.com/millermedeiros/requirejs-hogan-plugin/master/hgn.js > "$JS_FOLDER/lib/require/hgn.js"
curl https://raw.github.com/millermedeiros/requirejs-hogan-plugin/master/hogan.js > "$JS_FOLDER/lib/hogan.js"
# text plugin is a dependency
curl https://raw.github.com/requirejs/text/master/text.js > "$JS_FOLDER/lib/require/text.js"
fi
# Other Libs -----------
echo "\n -- updating moutjs --\n"
if $IS_SVN; then
find "$JS_FOLDER/lib/mout" ! -wholename '*.svn*' -type f -delete
else
rm -rf "$JS_FOLDER/lib/mout"
fi
git clone --depth 1 https://github.com/mout/mout.git "$SWAP_FOLDER/mout"
cp -R "$SWAP_FOLDER/mout/src/." "$JS_FOLDER/lib/mout/"
mv "$SWAP_FOLDER/mout/README.md" "$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
else
rm -rf "$JS_FOLDER/lib/millermedeiros"
fi
git clone --depth 1 https://github.com/millermedeiros/MM_js_lib.git "$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
else
rm -rf "$CSS_FOLDER/bss"
fi
git clone --depth 1 https://github.com/millermedeiros/basis.css.git "$SWAP_FOLDER/basis"
if $START_CSS; then
cp -R "$SWAP_FOLDER/basis/css/." "$CSS_FOLDER"
else
# we update only the "bss" folder otherwise it might overwrite user styles
cp -R "$SWAP_FOLDER/basis/css/bss/." "$CSS_FOLDER/bss/"
fi
mv "$SWAP_FOLDER/basis/README.md" "$CSS_FOLDER/bss/"
# Finish -----------
echo "\n -- clean swap folder --\n"
rm -rf "$SWAP_FOLDER"
echo "\n == FINISHED UPDATE == \n"
@mathiasbynens
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?)

@giuliandrimba
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".

@millermedeiros
Copy link
Author

update: I’ve been using http://volojs.org/ 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