Skip to content

Commit b16ffe3

Browse files
committed
优化编译脚本
1 parent ae755ff commit b16ffe3

File tree

4 files changed

+620
-109
lines changed

4 files changed

+620
-109
lines changed

build/build.sh

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
11
#!/usr/bin/env bash
22

33
function build() {
4-
ROOT=$(dirname $0)
4+
ROOT=$(dirname "$0")
55
JS_ROOT=$ROOT/../web/public/js
66
NAME="edge-admin"
77
DIST=$ROOT/"../dist/${NAME}"
88
OS=${1}
99
ARCH=${2}
1010
TAG=${3}
1111

12-
if [ -z $OS ]; then
12+
if [ -z "$OS" ]; then
1313
echo "usage: build.sh OS ARCH"
1414
exit
1515
fi
16-
if [ -z $ARCH ]; then
16+
if [ -z "$ARCH" ]; then
1717
echo "usage: build.sh OS ARCH"
1818
exit
1919
fi
20-
if [ -z $TAG ]; then
20+
if [ -z "$TAG" ]; then
2121
TAG="community"
2222
fi
2323

2424
# checking environment
2525
echo "checking required commands ..."
2626
commands=("zip" "unzip" "go" "find" "sed")
2727
for cmd in "${commands[@]}"; do
28-
if [ `which ${cmd}` ]; then
28+
if [ "$(which "${cmd}")" ]; then
2929
echo "checking ${cmd}: ok"
3030
else
3131
echo "checking ${cmd}: not found"
3232
return
3333
fi
3434
done
3535

36-
VERSION=$(lookup-version $ROOT/../internal/const/const.go)
36+
VERSION=$(lookup-version "$ROOT"/../internal/const/const.go)
3737
ZIP="${NAME}-${OS}-${ARCH}-${TAG}-v${VERSION}.zip"
3838

3939
# build edge-api
40-
APINodeVersion=$(lookup-version $ROOT"/../../EdgeAPI/internal/const/const.go")
40+
APINodeVersion=$(lookup-version "$ROOT""/../../EdgeAPI/internal/const/const.go")
4141
echo "building edge-api v${APINodeVersion} ..."
4242
EDGE_API_BUILD_SCRIPT=$ROOT"/../../EdgeAPI/build/build.sh"
43-
if [ ! -f $EDGE_API_BUILD_SCRIPT ]; then
43+
if [ ! -f "$EDGE_API_BUILD_SCRIPT" ]; then
4444
echo "unable to find edge-api build script 'EdgeAPI/build/build.sh'"
4545
exit
4646
fi
4747

48-
cd $ROOT"/../../EdgeAPI/build"
48+
cd "$ROOT""/../../EdgeAPI/build" || exit
4949
echo "=============================="
50-
./build.sh $OS $ARCH $TAG
50+
./build.sh "$OS" "$ARCH" $TAG
5151
echo "=============================="
52-
cd -
52+
cd - || exit
5353

5454
# generate files
5555
echo "generating files ..."
56-
go run -tags $TAG $ROOT/../cmd/edge-admin/main.go generate
57-
if [ `which uglifyjs` ]; then
56+
go run -tags $TAG "$ROOT"/../cmd/edge-admin/main.go generate
57+
if [ "$(which uglifyjs)" ]; then
5858
echo "compress to component.js ..."
59-
uglifyjs --compress --mangle -- ${JS_ROOT}/components.src.js > ${JS_ROOT}/components.js
59+
uglifyjs --compress --mangle -- "${JS_ROOT}"/components.src.js > "${JS_ROOT}"/components.js
6060
else
6161
echo "copy to component.js ..."
62-
cp ${JS_ROOT}/components.src.js ${JS_ROOT}/components.js
62+
cp "${JS_ROOT}"/components.src.js "${JS_ROOT}"/components.js
6363
fi
6464

6565
# create dir & copy files
6666
echo "copying ..."
67-
if [ ! -d $DIST ]; then
68-
mkdir $DIST
69-
mkdir $DIST/bin
70-
mkdir $DIST/configs
71-
mkdir $DIST/logs
67+
if [ ! -d "$DIST" ]; then
68+
mkdir "$DIST"
69+
mkdir "$DIST"/bin
70+
mkdir "$DIST"/configs
71+
mkdir "$DIST"/logs
7272
fi
7373

74-
cp -R $ROOT/../web $DIST/
75-
rm -f $DIST/web/tmp/*
76-
rm -rf $DIST/web/public/js/components
77-
rm -f $DIST/web/public/js/components.src.js
78-
cp $ROOT/configs/server.template.yaml $DIST/configs/
74+
cp -R "$ROOT"/../web "$DIST"/
75+
rm -f "$DIST"/web/tmp/*
76+
rm -rf "$DIST"/web/public/js/components
77+
rm -f "$DIST"/web/public/js/components.src.js
78+
cp "$ROOT"/configs/server.template.yaml "$DIST"/configs/
7979

8080
# change _plus.[ext] to .[ext]
8181
if [ "${TAG}" = "plus" ]; then
8282
echo "converting filenames ..."
8383
exts=("html" "js" "css")
8484
for ext in "${exts[@]}"; do
8585
pattern="*_plus."${ext}
86-
find $DIST/web/views -type f -name $pattern | \
86+
find "$DIST"/web/views -type f -name "$pattern" | \
8787
while read filename; do
88-
mv ${filename} "${filename/_plus."${ext}"/."${ext}"}"
88+
mv "${filename}" "${filename/_plus."${ext}"/."${ext}"}"
8989
done
9090
done
9191
fi
9292

9393
EDGE_API_ZIP_FILE=$ROOT"/../../EdgeAPI/dist/edge-api-${OS}-${ARCH}-${TAG}-v${APINodeVersion}.zip"
94-
cp $EDGE_API_ZIP_FILE $DIST/
95-
cd $DIST/
96-
unzip -q $(basename $EDGE_API_ZIP_FILE)
97-
rm -f $(basename $EDGE_API_ZIP_FILE)
98-
cd -
94+
cp "$EDGE_API_ZIP_FILE" "$DIST"/
95+
cd "$DIST"/ || exit
96+
unzip -q "$(basename "$EDGE_API_ZIP_FILE")"
97+
rm -f "$(basename "$EDGE_API_ZIP_FILE")"
98+
cd - || exit
9999

100100
# build
101-
echo "building "${NAME}" ..."
102-
env GOOS=$OS GOARCH=$ARCH go build -trimpath -tags $TAG -ldflags="-s -w" -o $DIST/bin/${NAME} $ROOT/../cmd/edge-admin/main.go
101+
echo "building ${NAME} ..."
102+
env GOOS="$OS" GOARCH="$ARCH" go build -trimpath -tags $TAG -ldflags="-s -w" -o "$DIST"/bin/${NAME} "$ROOT"/../cmd/edge-admin/main.go
103103

104104
# delete hidden files
105-
find $DIST -name ".DS_Store" -delete
106-
find $DIST -name ".gitignore" -delete
107-
find $DIST -name "*.less" -delete
108-
find $DIST -name "*.css.map" -delete
109-
find $DIST -name "*.js.map" -delete
105+
find "$DIST" -name ".DS_Store" -delete
106+
find "$DIST" -name ".gitignore" -delete
107+
find "$DIST" -name "*.less" -delete
108+
find "$DIST" -name "*.css.map" -delete
109+
find "$DIST" -name "*.js.map" -delete
110110

111111
# zip
112112
echo "zip files ..."
@@ -123,15 +123,15 @@ function build() {
123123

124124
function lookup-version() {
125125
FILE=$1
126-
VERSION_DATA=$(cat $FILE)
126+
VERSION_DATA=$(cat "$FILE")
127127
re="Version[ ]+=[ ]+\"([0-9.]+)\""
128128
if [[ $VERSION_DATA =~ $re ]]; then
129129
VERSION=${BASH_REMATCH[1]}
130-
echo $VERSION
130+
echo "$VERSION"
131131
else
132132
echo "could not match version"
133133
exit
134134
fi
135135
}
136136

137-
build $1 $2 $3
137+
build "$1" "$2" "$3"

dist/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*.zip
2-
shield-admin
2+
edge-admin

0 commit comments

Comments
 (0)