bin/zipjs
#!/bin/bash
# zipjs
#
#{{IS_NOTE
# Purpose:
# Copy and compress Javascript and CSS
# Description:
#
# History:
# Thu Jan 26 14:17:26 2006, Created by tomyeh
#}}IS_NOTE
#
#Copyright (C) 2006 Potix Corporation. All Rights Reserved.
#
#{{IS_RIGHT
# This program is distributed under GPL Version 3.0 in the hope that
# it will be useful, but WITHOUT ANY WARRANTY.
#}}IS_RIGHT
#
if [ $# != 5 ] ; then
echo "Usage:"
echo " zipjs jarfl bshjarfl bshcmd srcdir dstdir"
echo
echo "All files are copied from one directory to another."
echo "The JavaScript files are compressed during copying."
exit 1
fi
if [ ! -d "$4" ] ; then #nothing to copy
exit 0
fi
jarfl="$1"
if [ "${jarfl#/}" = "$jarfl" ] ; then
jarfl="$(pwd)/$jarfl"
fi
bshjar="$2"
if [ "${bshjar#/}" = "$bshjar" ] ; then
bshjar="$(pwd)/$bshjar"
fi
bshcmd="$3"
if [ "${bshcmd#/}" = "$bshcmd" ] ; then
bshcmd="$(pwd)/$bshcmd"
fi
dstdir="$5"
if [ "${dstdir#/}" = "$dstdir" ] ; then
dstdir="$(pwd)/$dstdir"
fi
if [ ! -f "$jarfl" ] ; then
echo "$jarfl not found"
exit 1
fi
if [ ! -f "$bshjar" ] ; then
echo "$bshjar not found"
exit 1
fi
if [ ! -f "$bshcmd" ] ; then
echo "$bshcmd not found"
exit 1
fi
#convert jarfl to window format
if [ "$TERM" = "cygwin" ] || [ "$OSTYPE" = "cygwin" ] ; then
jarfl=$(cygpath -wa $jarfl)
bshjar=$(cygpath -wa $bshjar)
bshcmd=$(cygpath -wa $bshcmd)
fi
failed=false
function zips
{
local dst="$1"
local parent=$4
for f in *; do
if [ "$f" != "CVS" ] && [ "$f" != ".svn" ] ; then
dstfl=$dst/$f
if [ -d "$f" ] ; then
(
cd "$f"
zips "$dstfl" "$f"
)
elif [ -f "$f" ] ; then
mkdir -p "$dst"
if [ ! -f "$dstfl" ] || [ "$f" -nt "$dstfl" ] ; then
local cvt=false
if [ "${f%.js}" != "$f" ] ; then
cvt=true
type=
elif [ "${f%.css.dsp}" != "$f" ] || [ "${f%.css}" != "$f" ] ; then
cvt=true
type="--type css"
fi
if [ $cvt = true ] ; then
echo Compress $f
if [ "$TERM" = "cygwin" ] || [ "$OSTYPE" = "cygwin" ] ; then
dstfl=$(cygpath -wa $dstfl)
fi
java -jar $jarfl --charset UTF-8 $type "$f" -o "$dstfl" 2>&1
if [ $? != 0 ] ; then
echo "Warning failed to compress, use copy instead: $f"
cvt=false
elif [ "$type" = "" ] ; then #JS
if [ "$TERM" = "cygwin" ] || [ "$OSTYPE" = "cygwin" ] ; then
srcfile=$(cygpath -wa $dst/${f%.js}.src.js)
else
srcfile=$dst/${f%.js}.src.js
fi
java -classpath $bshjar bsh.Interpreter $bshcmd "./$f" "$srcfile"
#always make a copy so we can use them if we want to debug them
fi
fi
if [ $cvt = false ] ; then
echo copy $f
cp -p ./"$f" $dst
#$f might starts with -
if [ $? != 0 ] ; then
echo "Failed:"
echo " cp -p $f $dst"
failed=true
fi
fi
fi
fi
fi
done
cd ..
}
cd $4
zips "$dstdir"
if [ $failed = true ] ; then
exit 1
fi