summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE-os/build-ecomportal-fe.sh
blob: 8fc199d5a60589152adff71463631451913ac9a6 (plain)
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
173
174
175
176
177
178
179
180
181
#!/bin/sh

# Script name : build_ecompportal_fe.sh
# Script purpose : To have an easy way to build the front-end part of the eComp portal
# Pre requisites :
# 1. Your home directory must reside at /home
# 2. Your server must have a 'Node' installation
#----------------------------------------------------------------------------------------


################################################
### Functions
################################################
function log_message() {
msgType=$1
message=$2

if [ ${msgType} == "I" ]; then
printf "\033[32m %s \n\033[0m" "INF - ${message}"
elif [ ${msgType} == "E" ]; then
printf "\033[31m %s \n\033[0m" "ERR - ${message}"
else
echo "${msgType} - ${message}";
fi
}



function exit_with_error() {

log_message "E" ""
log_message "E" "$1"
log_message "E" ""

exit 1
}



################################################
### Hard coded information.
################################################
NVM_DIR="/home/${USER}/.nvm"
NODE_VERSION=v0.12.4
SCRIPT_USAGE="USAGE: $0 [ dev | ci | integ | qa ]"



################################################
### Verify arguments
################################################
log_message "I" "Checking command line arguments."
if [ $# == 1 ]; then
if [ $1 == "ci" -o $1 == "integ" -o $1 == "dev" -o $1 == "qa" ]; then
BUILD_BY_ENV=$1
else
exit_with_error "The environment '$1' is invalid."
fi
else
log_message "E" ""
log_message "E" "$SCRIPT_USAGE"
log_message "E" ""
exit 1
fi
log_message "I" "OK."
log_message "I" ""



################################################
### Set the node environment.
################################################
log_message "I" "Set the node environment."
if [ -s "$NVM_DIR/nvm.sh" ]; then
# This loads nvm
. "$NVM_DIR/nvm.sh"
if [ $? != 0 ]; then
exit_with_error "Cannot load the NODE env."
fi
else
exit_with_error "The nvm.sh script does not exist."
fi
log_message "I" "OK."
log_message "I" ""



################################################
### Set the node version manager version.
################################################
log_message "I" "Set the node version manager version."
nvm use v0.12.4
TOOLS_ROOT_FOLDER=${NVM_DIR}/versions/node/${NODE_VERSION}/bin
log_message "I" "OK."
log_message "I" ""



################################################
### Set the proxy servers.
################################################
log_message "I" "Set the proxy servers."
log_message "I" "OK."
log_message "I" ""



################################################
### Install bower, if neeeded.
################################################
log_message "I" "Install bower, if neeeded."
if [ ! -e ${TOOLS_ROOT_FOLDER}/bower ]; then
npm install -g bower
if [ $? != 0 ]; then
exit_with_error "Cannot install bower."
fi
fi
log_message "I" "OK."
log_message "I" ""



################################################
### Install grunt, if neeeded.
################################################
log_message "I" "Install grunt, if neeeded."
if [ ! -e ${TOOLS_ROOT_FOLDER}/grunt ]; then
npm config set ca ""
npm install -g grunt-cli

if [ $? != 0 ]; then
exit_with_error "Cannot install grunt."
fi
fi
log_message "I" "OK."
log_message "I" ""



################################################
### Run the Node package manager (NPM).
################################################
log_message "I" "Run the Node package manager (npm install)."
npm install
if [ $? != 0 ]; then
exit_with_error "Cannot run 'npm install'."
fi
log_message "I" "OK."
log_message "I" ""



################################################
### Install the Bower components.
################################################
log_message "I" "Install the Bower components."
bower install
if [ $? != 0 ]; then
exit_with_error "Cannot run 'npm install'."
fi
log_message "I" "OK."
log_message "I" ""



################################################
### Build the application.
################################################
log_message "I" "Build the application."
grunt build --env=${BUILD_BY_ENV}
if [ $? != 0 ]; then
exit_with_error "Cannot run 'grunt build --env=${BUILD_BY_ENV}'."
fi
log_message "I" "OK."
log_message "I" ""



log_message "I" ""
log_message "I" "Done."
log_message "I" ""