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