

mkdir build
cp -r web/* build/
echo "$1";
if [ ! -z "$1" ]; then
	echo "asdas";
	sed -i "s|http://localhost:8080|$1|g" build/js/ip.js
fi


rm build/css/styles.css

uglifycss --output build/css/styles.min.css web/css/styles.css
sed -i 's|<link rel="stylesheet" type="text/css" href="css/styles.css">|<link rel="stylesheet" type="text/css" href="css/styles.min.css">|g' build/index.html
sed -i 's|<link rel="stylesheet" type="text/css" href="css/styles.css">|<link rel="stylesheet" type="text/css" href="css/styles.min.css">|g' build/about.html

rm build/js/jszip.min.js build/js/editor.js build/js/FileSaver.js 

cat web/js/jszip.min.js web/js/editor.js web/js/FileSaver.js build/js/ip.js | uglifyjs > build/js/index.min.js

sed -i 's|<script src="js/editor.js"></script>|<script src="js/index.min.js"></script>|g' build/index.html
sed -i 's|<script src="js/ip.js"></script>||g' build/index.html
sed -i 's|<script src="js/jszip.min.js"></script>||g' build/index.html
sed -i 's|<script src="js/FileSaver.js"></script>||g' build/index.html

rm build/creta/src/js/creta-core.js build/creta/src/js/creta-ui.js build/creta/src/js/creta.js build/creta/src/js/beautify-html.js

cat web/creta/src/js/creta-core.js web/creta/src/js/creta-ui.js web/creta/src/js/creta.js web/creta/src/js/beautify-html.js | uglifyjs > build/creta/src/js/creta.min.js

sed -i 's|<script src="creta/src/js/creta-core.js"></script>|<script src="creta/src/js/creta.min.js"></script>|g' build/index.html
sed -i 's|<script src="creta/src/js/creta-ui.js"></script>||g' build/index.html
sed -i 's|<script src="creta/src/js/creta.js"></script>||g' build/index.html
sed -i 's|<script src="creta/src/js/beautify-html.js"></script>||g' build/index.html

rm build/js/tedi/html2tedi.js build/js/tedi/tedi2html.js build/js/tedi/tedi2lang.js build/js/tedi/tedi2tex.js build/js/tedi/tedi2md.js

cat web/js/tedi/tedi2lang.js web/js/tedi/html2tedi.js web/js/tedi/tedi2html.js web/js/tedi/tedi2tex.js web/js/tedi/tedi2md.js | uglifyjs > build/js/tedi/tedi2langs.js

sed -i 's|<script src="js/tedi/tedi2lang.js"></script>|<script src="js/tedi/tedi2langs.js"></script>|g' build/index.html
sed -i 's|<script src="js/tedi/html2tedi.js"></script>||g' build/index.html
sed -i 's|<script src="js/tedi/tedi2tex.js"></script>||g' build/index.html
sed -i 's|<script src="js/tedi/tedi2html.js"></script>||g' build/index.html
sed -i 's|<script src="js/tedi/tedi2md.js"></script>||g' build/index.html

rm -r build/creta/src/icons/ build/creta/test/

cp -r web/js/output build/js/

cp web/js/mathjax.js build/js/mathjax.js
