3 # Script name : build_ecompportal_fe.sh
4 # Script purpose : To have an easy way to build the front-end part of the eComp portal
6 # 1. Your home directory must reside at /home
7 # 2. Your server must have a 'Node' installation
8 #----------------------------------------------------------------------------------------
11 ################################################
13 ################################################
14 function log_message() {
18 if [ ${msgType} == "I" ]; then
19 printf "\033[32m %s \n\033[0m" "INF - ${message}"
20 elif [ ${msgType} == "E" ]; then
21 printf "\033[31m %s \n\033[0m" "ERR - ${message}"
23 echo "${msgType} - ${message}";
29 function exit_with_error() {
40 ################################################
41 ### Hard coded information.
42 ################################################
43 NVM_DIR="/home/${USER}/.nvm"
45 SCRIPT_USAGE="USAGE: $0 [ dev | ci | integ | qa ]"
49 ################################################
51 ################################################
52 log_message "I" "Checking command line arguments."
54 if [ $1 == "ci" -o $1 == "integ" -o $1 == "dev" -o $1 == "qa" ]; then
57 exit_with_error "The environment '$1' is invalid."
61 log_message "E" "$SCRIPT_USAGE"
70 ################################################
71 ### Set the node environment.
72 ################################################
73 log_message "I" "Set the node environment."
74 if [ -s "$NVM_DIR/nvm.sh" ]; then
78 exit_with_error "Cannot load the NODE env."
81 exit_with_error "The nvm.sh script does not exist."
88 ################################################
89 ### Set the node version manager version.
90 ################################################
91 log_message "I" "Set the node version manager version."
93 TOOLS_ROOT_FOLDER=${NVM_DIR}/versions/node/${NODE_VERSION}/bin
99 ################################################
100 ### Set the proxy servers.
101 ################################################
102 log_message "I" "Set the proxy servers."
103 log_message "I" "OK."
108 ################################################
109 ### Install bower, if neeeded.
110 ################################################
111 log_message "I" "Install bower, if neeeded."
112 if [ ! -e ${TOOLS_ROOT_FOLDER}/bower ]; then
115 exit_with_error "Cannot install bower."
118 log_message "I" "OK."
123 ################################################
124 ### Install grunt, if neeeded.
125 ################################################
126 log_message "I" "Install grunt, if neeeded."
127 if [ ! -e ${TOOLS_ROOT_FOLDER}/grunt ]; then
129 npm install -g grunt-cli
132 exit_with_error "Cannot install grunt."
135 log_message "I" "OK."
140 ################################################
141 ### Run the Node package manager (NPM).
142 ################################################
143 log_message "I" "Run the Node package manager (npm install)."
146 exit_with_error "Cannot run 'npm install'."
148 log_message "I" "OK."
153 ################################################
154 ### Install the Bower components.
155 ################################################
156 log_message "I" "Install the Bower components."
159 exit_with_error "Cannot run 'npm install'."
161 log_message "I" "OK."
166 ################################################
167 ### Build the application.
168 ################################################
169 log_message "I" "Build the application."
170 grunt build --env=${BUILD_BY_ENV}
172 exit_with_error "Cannot run 'grunt build --env=${BUILD_BY_ENV}'."
174 log_message "I" "OK."
180 log_message "I" "Done."