Skip to content

Instantly share code, notes, and snippets.

@markprzepiora
Last active January 4, 2016 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markprzepiora/8606858 to your computer and use it in GitHub Desktop.
Save markprzepiora/8606858 to your computer and use it in GitHub Desktop.
copy_bower_components
#!/usr/bin/env bash
set -e
# copy_bower_components - A very simple bash script for copying your Bower
# components over to your rails vendor/assets folder.
#
# Copyright (c) 2013 Mark Przepiora
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
jspath="./vendor/assets/javascripts"
bowerpath="./bower_components"
file_exists() {
if [ -a "$1" ]; then
return 0
else
return 1
fi
}
diff_info() {
echo -n "$(diff -u "$1" "$2" | diffstat | tail -1 | cut -c 2-)"
}
copy_asset() {
fullname="$bowerpath"/"$1"
if [ -z "$2" ]; then
basename="$(basename "$fullname")"
else
basename="$2"
fi
fulltargetname="$3"/"$basename"
if ! file_exists "$fullname"; then
echo "The file $fullname does not exist"
return 1
fi
echo -n "Copying $fullname -> $fulltargetname "
if file_exists "$fulltargetname"; then
echo "[$(diff_info "$fullname" "$fulltargetname")]"
else
echo "[new file]"
fi
cp "$fullname" "$fulltargetname"
}
js() {
copy_asset "$1" "$2" "$jspath"
}
js underscore/underscore.js
js gravtastic/vendor/assets/javascripts/gravtastic.coffee
js gravtastic/vendor/assets/javascripts/md5.js
js inview/jquery.inview.js
js momentjs/min/moment.min.js
js html5shiv/dist/html5shiv.js
js filesize/lib/filesize.js
js selectize/dist/js/standalone/selectize.js
js jslider/bin/jquery.slider.min.js
js underscore.string/dist/underscore.string.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment