fix JS minification issues.

This commit is contained in:
kunw 2016-07-14 14:35:29 +08:00
parent 1bcf243d8b
commit b163735e53

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
set -e
echo "This shell will minify the Javascript in Harbor project."
echo "Usage: #jsminify [src] [dest]"
@ -9,26 +9,26 @@ rm -rf $2 /tmp/harbor.app.temp.js
BASEPATH=/go/bin
#concat the js files from js include file
echo "Concat js files..."
cat $1 |while read LINE
cat $1 | while read LINE || [[ -n $LINE ]]
do
if [ -n "$LINE" ]
then
TEMP="$BASEPATH""$LINE"
cat `echo "$TEMP" | sed 's/<script src=\"//g' |sed 's/\"><\/script>//g'` >> /tmp/harbor.app.temp.js
cat `echo "$TEMP" | sed 's/<script src=\"//g' | sed 's/\"><\/script>//g'` >> /tmp/harbor.app.temp.js
printf "\n" >> /tmp/harbor.app.temp.js
fi
done
#remove space
echo "Remove space.."
sed 's/ //g' -i /tmp/harbor.app.temp.js
sed 's/ \+/ /g' -i /tmp/harbor.app.temp.js
#remove '//' and '/*'
echo "Remove '//'and '/*' annotation..."
sed '/^\/\//'d -i /tmp/harbor.app.temp.js
sed '/\/\*/{/\*\//d;:a;N;/\*\//d;ba};s,//.*,,' -i /tmp/harbor.app.temp.js
cat > $2 << EOF
/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
@ -56,4 +56,4 @@ rm -rf /tmp/harbor.app.temp.js
echo "Done."
exit 0