if [ ! -d output ]; then
	mkdir output
fi

echo " *** Building Themes *** "

if [ -d src/uwt-web/common ]; then
	pushd src/uwt-web/common

	# first compile common CSS
	# since lessc doesn't support multiple files, we have to cat =(^.^)= them first :(
	cat *.less > ../common.less
	lessc --verbose --plugin=less-plugin-clean-css ../common.less ../../../output/common.css
	rm ../common.less

	popd
fi

if [ -d src/uwt-web/themes ]; then
	
	if [ ! -d output/themes ]; then
		mkdir output/themes
	fi
	
	# for each dir in themes dir, compile its own .css file
	for theme in $(ls src/uwt-web/themes); do
		cat src/uwt-web/themes/$theme/*.less > src/uwt-web/themes/$theme.less
		lessc --verbose --plugin=less-plugin-clean-css src/uwt-web/themes/$theme.less output/themes/$theme.css
		rm src/uwt-web/themes/$theme.less
	done

fi

echo " *** Building Scripts *** "

if [ -d src/uwt-web/scripts ]; then

	cat src/uwt-web/scripts/*.js src/uwt-web/scripts/controls/*.js > src/uwt-web/scripts.js
	jsmin src/uwt-web/scripts.js > output/uwt.min.js
	rm src/uwt-web/scripts.js

fi

echo " *** Build Completed ***"


