Merge pull request #542 from wknet123/master

Update for JS minification.
This commit is contained in:
kun wang 2016-07-14 15:00:09 +08:00 committed by GitHub
commit 48af6cbfb5
4 changed files with 14 additions and 14 deletions

View File

@ -36,7 +36,7 @@ db_password = root123
self_registration = on
#Turn on or off the options to control UI whether to use compressed js file
use_compressed_js = off
use_compressed_js = on
#Number of job workers in job service, default is 3
max_job_workers = 3

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

View File

@ -13,7 +13,7 @@ LDAP_URL=$ldap_url
LDAP_BASE_DN=$ldap_basedn
UI_SECRET=$ui_secret
SELF_REGISTRATION=$self_registration
PRODUCTION=$use_compressed_js
USE_COMPRESSED_JS=$use_compressed_js
LOG_LEVEL=debug
GODEBUG=netdns=cgo
EXT_ENDPOINT=$ui_url

View File

@ -21,7 +21,7 @@ type BaseController struct {
SelfRegistration bool
IsAdmin bool
AuthMode string
Production bool
UseCompressedJS bool
}
type langType struct {
@ -99,13 +99,13 @@ func (b *BaseController) Prepare() {
b.AuthMode = authMode
b.Data["AuthMode"] = b.AuthMode
production := os.Getenv("PRODUCTION")
if production == "on" {
b.Production = true
useCompressedJS := os.Getenv("USE_COMPRESSED_JS")
if useCompressedJS == "on" {
b.UseCompressedJS = true
}
if _, err := os.Stat(filepath.Join("static", "resources", "js", "harbor.app.min.js")); os.IsNotExist(err) {
b.Production = false
b.UseCompressedJS = false
}
}
@ -117,7 +117,7 @@ func (b *BaseController) Forward(title, templateName string) {
b.LayoutSections = make(map[string]string)
b.LayoutSections["HeaderInclude"] = filepath.Join(prefixNg, viewPath, "header-include.htm")
if b.Production {
if b.UseCompressedJS {
b.LayoutSections["HeaderScriptInclude"] = filepath.Join(prefixNg, viewPath, "script-min-include.htm")
} else {
b.LayoutSections["HeaderScriptInclude"] = filepath.Join(prefixNg, viewPath, "script-include.htm")