Skip to content

Commit

Permalink
Add support to file modification verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Furlan committed May 27, 2011
1 parent 418a1a8 commit 153bca0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/minify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ if [ $# -lt 1 ]; then
exit 1
fi

## compare the modified date of two files
is_file_modified() {
[ $# -lt 2 ] && return 0

MOD1=$(stat "${1}" | grep ^Modify:)
MOD2=$(stat "${2}" | grep ^Modify:)

if [[ "$MOD1" > "$MOD2" ]]; then
return 1
else
return 0
fi
}

## minify all modified files under $BASEDIR
BASEDIR=$(cd $(dirname $1) && echo $PWD)
find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do

Expand All @@ -21,13 +36,19 @@ find "$BASEDIR" -type f | egrep -v '\.min\.' | while read FILE; do
css|js)
DEST="${NAME}.min.${TYPE}"

is_file_modified "$FILE" "$DEST"
[ "$?" = "1" ] || continue

echo "Compressing: ${DEST}"
java -jar "${YUICOMPRESS}" "${FILE}" > "${DEST}"
;;

xml)
DEST="${FILE}.gz"

is_file_modified "$FILE" "$DEST"
[ "$?" = "1" ] || continue

echo "Compressing: ${DEST}"
gzip -c "${FILE}" > "${DEST}"
;;
Expand Down

0 comments on commit 153bca0

Please sign in to comment.