#!/bin/sh

cd /www/web/public/js

#change all files to unix format
svnupdateunix

#add jsmin directory to svn
PATHS=`find /www/web/public/js  -type d`

if [ ! -d '/www/web/public/jsmin' ];then
	mkdir  '/www/web/public/jsmin'
	svn add  '/www/web/public/jsmin'
fi

for path in $PATHS
do
if [ `echo $path | grep -c ".svn"` -eq 0 ];then
	pathnew=`echo $path | sed -e 's/\/www\/web\/public\/js\//\/www\/web\/public\/jsmin\//g'`
	
	if [ ! -d $pathnew ];then
		mkdir -p $pathnew
	fi
	echo $pathnew
	svn add $pathnew
	
fi
done
svn commit -m 'add jsmin directories'

FILES=`find /www/web/public/js -name '*.js' -type f`

for FILE in $FILES
do
FILENEW=`echo $FILE | sed -e 's/\/www\/web\/public\/js\//\/www\/web\/public\/jsmin\//g'`

FILEPATH=`echo $FILENEW | sed 's/[^\/]*$//'`

echo "FILE:$FILE"
yuicompressor $FILE -o $FILENEW --charset utf-8
svn add $FILENEW

done

svn commit -m 'compress js file'

