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