UserController tests up
[portal.git] / ecomp-portal-FE-os / build-ecomportal-fe.sh
1 #!/bin/sh
2
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
5 # Pre requisites :
6 # 1. Your home directory must reside at /home
7 # 2. Your server must have a 'Node' installation
8 #----------------------------------------------------------------------------------------
9
10
11 ################################################
12 ### Functions
13 ################################################
14 function log_message() {
15 msgType=$1
16 message=$2
17
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}"
22 else
23 echo "${msgType} - ${message}";
24 fi
25 }
26
27
28
29 function exit_with_error() {
30
31 log_message "E" ""
32 log_message "E" "$1"
33 log_message "E" ""
34
35 exit 1
36 }
37
38
39
40 ################################################
41 ### Hard coded information.
42 ################################################
43 NVM_DIR="/home/${USER}/.nvm"
44 NODE_VERSION=v0.12.4
45 SCRIPT_USAGE="USAGE: $0 [ dev | ci | integ | qa ]"
46
47
48
49 ################################################
50 ### Verify arguments
51 ################################################
52 log_message "I" "Checking command line arguments."
53 if [ $# == 1 ]; then
54 if [ $1 == "ci" -o $1 == "integ" -o $1 == "dev" -o $1 == "qa" ]; then
55 BUILD_BY_ENV=$1
56 else
57 exit_with_error "The environment '$1' is invalid."
58 fi
59 else
60 log_message "E" ""
61 log_message "E" "$SCRIPT_USAGE"
62 log_message "E" ""
63 exit 1
64 fi
65 log_message "I" "OK."
66 log_message "I" ""
67
68
69
70 ################################################
71 ### Set the node environment.
72 ################################################
73 log_message "I" "Set the node environment."
74 if [ -s "$NVM_DIR/nvm.sh" ]; then
75 # This loads nvm
76 . "$NVM_DIR/nvm.sh"
77 if [ $? != 0 ]; then
78 exit_with_error "Cannot load the NODE env."
79 fi
80 else
81 exit_with_error "The nvm.sh script does not exist."
82 fi
83 log_message "I" "OK."
84 log_message "I" ""
85
86
87
88 ################################################
89 ### Set the node version manager version.
90 ################################################
91 log_message "I" "Set the node version manager version."
92 nvm use v0.12.4
93 TOOLS_ROOT_FOLDER=${NVM_DIR}/versions/node/${NODE_VERSION}/bin
94 log_message "I" "OK."
95 log_message "I" ""
96
97
98
99 ################################################
100 ### Set the proxy servers.
101 ################################################
102 log_message "I" "Set the proxy servers."
103 log_message "I" "OK."
104 log_message "I" ""
105
106
107
108 ################################################
109 ### Install bower, if neeeded.
110 ################################################
111 log_message "I" "Install bower, if neeeded."
112 if [ ! -e ${TOOLS_ROOT_FOLDER}/bower ]; then
113 npm install -g bower
114 if [ $? != 0 ]; then
115 exit_with_error "Cannot install bower."
116 fi
117 fi
118 log_message "I" "OK."
119 log_message "I" ""
120
121
122
123 ################################################
124 ### Install grunt, if neeeded.
125 ################################################
126 log_message "I" "Install grunt, if neeeded."
127 if [ ! -e ${TOOLS_ROOT_FOLDER}/grunt ]; then
128 npm config set ca ""
129 npm install -g grunt-cli
130
131 if [ $? != 0 ]; then
132 exit_with_error "Cannot install grunt."
133 fi
134 fi
135 log_message "I" "OK."
136 log_message "I" ""
137
138
139
140 ################################################
141 ### Run the Node package manager (NPM).
142 ################################################
143 log_message "I" "Run the Node package manager (npm install)."
144 npm install
145 if [ $? != 0 ]; then
146 exit_with_error "Cannot run 'npm install'."
147 fi
148 log_message "I" "OK."
149 log_message "I" ""
150
151
152
153 ################################################
154 ### Install the Bower components.
155 ################################################
156 log_message "I" "Install the Bower components."
157 bower install
158 if [ $? != 0 ]; then
159 exit_with_error "Cannot run 'npm install'."
160 fi
161 log_message "I" "OK."
162 log_message "I" ""
163
164
165
166 ################################################
167 ### Build the application.
168 ################################################
169 log_message "I" "Build the application."
170 grunt build --env=${BUILD_BY_ENV}
171 if [ $? != 0 ]; then
172 exit_with_error "Cannot run 'grunt build --env=${BUILD_BY_ENV}'."
173 fi
174 log_message "I" "OK."
175 log_message "I" ""
176
177
178
179 log_message "I" ""
180 log_message "I" "Done."
181 log_message "I" ""