This repository has been archived by the owner on Mar 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild
executable file
·172 lines (137 loc) · 3.99 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
##--------------------------------------------------------------------
## Copyright (c) 2019 Dianomic Systems Inc.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##--------------------------------------------------------------------
##
## Author: Mohd. Shariq
##
set -e
__version__=`cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[" ,]//g'`
# Colors
CPFX="\033["
CRESET="${CPFX}0m" # Text Reset
CERR="${CPFX}1;31m"
CINFO="${CPFX}1;32m"
CWARN="${CPFX}0;33m"
############################################################
# Usage text for this script
############################################################
USAGE="${__version__}
DESCRIPTION
This script build foglamp-gui distribution artifacts
OPTIONS
Multiple commands can be specified but they all must be
specified separately (-hv is not supported).
-h, --help Display this help text
-v, --version Display this script's version information
-c, --clean Clean and build dependencies
--clean-start Clean the build dependencies and start
EXAMPLE
$0 --version"
#########################
# functions def
#########################
remove_unwanted_files () {
find dist/assets/* | grep -v "favicon.ico" | xargs rm -rf
rm dist/*.eot
rm dist/*.svg
# rm dist/*.ttf
rm dist/*.woff
# if built on mac
rm -rf .DS_Store
}
compress_bundle_js_files () {
gzip --keep dist/*.bundle.js
}
show_files_with_size () {
for f in dist/*.*; do
FILE_SIZE=$(du -h "$f")
echo "${FILE_SIZE}"
done
}
clean(){
echo -e INFO: "${CINFO} Cleaning the build and dependencies ... ${CRESET}"
yarn clean
}
build () {
echo -e INFO: "${CINFO} Installing dependencies ... ${CRESET}"
yarn install
echo -e INFO: "${CINFO} Creating production build ... ${CRESET}"
yarn build
echo -e INFO: "${CINFO} Build distribution contents ... ${CRESET}"
show_files_with_size
T_SIZE=$(du -hs dist)
echo -e INFO " ${CWARN} Size: ${T_SIZE} ${CRESET}"
echo -e INFO: "${CINFO} Removing unwanted contents ... ${CRESET}"
remove_unwanted_files
# echo "Compressing ..."
# compress_bundle_js_files
T_SIZE=$(du -hs dist)
echo -e INFO: "${CINFO} Deployable dist size ${CWARN} ${T_SIZE} ${CRESET}"
# echo "Copying custom nginx conf file ..."
# cp nginx.conf dist/
RELEASABLE_BUILD="foglamp-gui-${__version__}.tar.gz"
echo -e INFO: "${CINFO} Creating compressed build artifacts for release ... ${CRESET}"
tar -zcvf ${RELEASABLE_BUILD} dist &>/dev/null
echo "Created ${RELEASABLE_BUILD}"
echo -e INFO: "${CINFO} Done. ${CRESET}"
}
############################################################
# Execute the command specified in $OPTION
############################################################
execute_command() {
if [[ "$OPTION" == "HELP" ]]
then
echo "${USAGE}"
elif [[ "$OPTION" == "VERSION" ]]
then
echo $__version__
elif [[ "$OPTION" == "CLEAN" ]]
then
clean
elif [[ "$OPTION" == "CLEAN_START" ]]
then
clean
build
fi
}
############################################################
# Process arguments
############################################################
if [ $# -gt 0 ]
then
for i in "$@"
do
case $i in
-h|--help)
OPTION="HELP"
;;
-v|--version)
OPTION="VERSION"
;;
-c|--clean)
OPTION="CLEAN"
;;
--clean-start)
OPTION="CLEAN_START"
;;
*)
echo "Unrecognized option: $i"
esac
execute_command
done
else
build
fi