Created
April 21, 2013 20:11
-
-
Save Arood/5430904 to your computer and use it in GitHub Desktop.
Watches for changes in JavaScript and Sass-folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
JS_PATH="_js" | |
FINAL_JS="scripts.js" | |
SASS_PATH="_sass" | |
FINAL_CSS="." | |
sha=0 | |
previous_sha=0 | |
update_sha() | |
{ | |
sha=`ls -lRT $JS_PATH $SASS_PATH | gsha1sum` | |
} | |
build () { | |
# Build/make commands here | |
rm $FINAL_JS | |
touch $FINAL_JS | |
cat $JS_PATH/*.js >> $FINAL_JS | |
echo " \033[0;32m$FINAL_JS\033[0m" | |
sass --update $SASS_PATH:$FINAL_CSS | |
} | |
changed () { | |
echo " ≫ Change detected. Rebuilding..." | |
build | |
previous_sha=$sha | |
} | |
compare () { | |
update_sha | |
if [[ $sha != $previous_sha ]] ; then changed; fi | |
} | |
run () { | |
update_sha | |
previous_sha=$sha | |
while true; do | |
compare | |
read -s -t 1 && ( | |
echo " ≫ Forced rebuild..." | |
build | |
) | |
done | |
} | |
echo " ≫ Watching for changes. Press Ctrl-C to stop. Press enter to force rebuild." | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment