1
1
#! /bin/bash
2
2
3
3
NODE_VERSION=$( < " ${SCRIPT_DIR} /../../../NODE_VERSION" )
4
- NPM=" ${SCRIPT_DIR} /node/bin/npm"
5
4
6
5
# Prints the arguments and their descriptions to the console
7
6
function print_usage() {
@@ -35,7 +34,7 @@ function print_usage() {
35
34
if [[ -d " ${SCRIPT_DIR} /../../dist/" ]]; then
36
35
pushd " ${SCRIPT_DIR} /../.."
37
36
echo " Server options:"
38
- " ${NPM} " run start -- --help
37
+ npm run start -- --help
39
38
popd
40
39
fi
41
40
exit 1
@@ -76,40 +75,21 @@ function parse_args() {
76
75
}
77
76
78
77
function check_version() { # current_version #min_version
79
- # check if same string
80
- if [ -z " $2 " ] || [ " $1 " = " $2 " ]; then
78
+ local current=" $1 "
79
+ local minimum=" $2 "
80
+
81
+ # Check if no minimum or both are the same
82
+ if [ -z " $minimum " ] || [ " $current " = " $minimum " ]; then
81
83
return 0
82
84
fi
83
85
84
- local i current minimum
85
-
86
- IFS=" ." read -r -a current <<< $1
87
- IFS=" ." read -r -a minimum <<< $2
88
-
89
- # fill empty fields in current with zeros
90
- for (( i= ${# current[@]} ; i< ${# minimum[@]} ; i++ ))
91
- do
92
- current[i]=0
93
- done
94
-
95
- for (( i= 0 ; i< ${# current[@]} ; i++ ))
96
- do
97
- if [[ -z ${minimum[i]} ]]; then
98
- # fill empty fields in minimum with zeros
99
- minimum[i]=0
100
- fi
86
+ local ordered=$( printf " %s\n%s\n" " $minimum " " $current " | sort -V | head -n1)
101
87
102
- if (( 10 #${current[i]} > 10 #${minimum[i]} )) ; then
103
- return 1
104
- fi
105
-
106
- if (( 10 #${current[i]} < 10 #${minimum[i]} )) ; then
107
- return 2
108
- fi
109
- done
110
-
111
- # if got this far string is the same once we added missing 0
112
- return 0
88
+ if [ " $ordered " = " $minimum " ]; then
89
+ return 1
90
+ else
91
+ return 2
92
+ fi
113
93
}
114
94
115
95
function check_and_install() { # dep_name #get_version_string #version_min #install_command
@@ -168,15 +148,9 @@ function setup_node() {
168
148
# navigate to project root
169
149
pushd " ${SCRIPT_DIR} /../../.." > /dev/null
170
150
171
- # setup the path so we're using our node. required when calling npm
172
- PATH=" ${SCRIPT_DIR} /node/bin:$PATH "
173
-
174
- node_version=" "
175
- if [[ -f " ${SCRIPT_DIR} /node/bin/node" ]]; then
176
- node_version=$( " ${SCRIPT_DIR} /node/bin/node" --version)
177
- fi
151
+ local node_version=$( " node" --version)
178
152
179
- node_url=" "
153
+ local node_url=" "
180
154
if [ " $( uname) " == " Darwin" ]; then
181
155
arch=$( uname -m)
182
156
if [[ $arch == x86_64* ]]; then
@@ -190,16 +164,27 @@ function setup_node() {
190
164
else
191
165
node_url=" https://nodejs.org/dist/$NODE_VERSION /node-$NODE_VERSION -linux-x64.tar.gz"
192
166
fi
193
- check_and_install " ${SCRIPT_DIR} /node/bin/node" " $node_version " " $NODE_VERSION " " curl $node_url --output node.tar.xz
167
+
168
+ check_and_install " node" " $node_version " " $NODE_VERSION " " curl $node_url --output node.tar.xz
194
169
&& tar -xf node.tar.xz
195
170
&& rm node.tar.xz
196
171
&& mv node-v*-*-* \" ${SCRIPT_DIR} /node\" "
197
172
198
- if [ $? -eq 1 ] || [ " $INSTALL_DEPS " == " 1" ]; then
173
+ if [ $? -eq 1 ]; then
174
+ # installed node, point PATH to it
175
+ PATH=" ${SCRIPT_DIR} /node/bin:$PATH "
176
+ fi
177
+
178
+ # if node_modules doesnt exist or the package-lock file is newer than node_modules, install deps
179
+ if [ ! -d node_modules ] || [ ../package-lock.json -nt node_modules ] || [ " $INSTALL_DEPS " == " 1" ]; then
199
180
echo " Installing dependencies..."
200
- " ${NPM} " install
181
+ npm install
201
182
fi
202
183
184
+ # log node version for audits
185
+ echo " Using node version: $( node --version) "
186
+ echo " Using NPM version: $( npm --version) "
187
+
203
188
popd > /dev/null
204
189
}
205
190
@@ -209,14 +194,14 @@ function setup_libraries() {
209
194
if [ ! -d " ${SCRIPT_DIR} /../../../Common/dist/" ] || [ " $BUILD_LIBRARIES " == " 1" ]; then
210
195
pushd " ${SCRIPT_DIR} /../../../Common" > /dev/null
211
196
echo " Building common library."
212
- " ${NPM} " run build:cjs
197
+ npm run build:cjs
213
198
popd > /dev/null
214
199
fi
215
200
216
201
if [ ! -d " ${SCRIPT_DIR} /../../../Signalling/dist/" ] || [ " $BUILD_LIBRARIES " == " 1" ]; then
217
202
pushd " ${SCRIPT_DIR} /../../../Signalling" > /dev/null
218
203
echo " Building signalling library."
219
- " ${NPM} " run build:cjs
204
+ npm run build:cjs
220
205
popd > /dev/null
221
206
fi
222
207
@@ -242,13 +227,13 @@ function setup_frontend() {
242
227
echo " Building Typescript Frontend."
243
228
# Using our bundled NodeJS, build the web frontend files
244
229
pushd " ${SCRIPT_DIR} /../../../Frontend/library" > /dev/null
245
- " ${NPM} " run build:cjs
230
+ npm run build:cjs
246
231
popd > /dev/null
247
232
pushd " ${SCRIPT_DIR} /../../../Frontend/ui-library" > /dev/null
248
- " ${NPM} " run build:cjs
233
+ npm run build:cjs
249
234
popd > /dev/null
250
235
pushd " ${SCRIPT_DIR} /../../../Frontend/implementations/typescript" > /dev/null
251
- " ${NPM} " run build:dev
236
+ npm run build:dev
252
237
popd > /dev/null
253
238
else
254
239
echo ' Skipping building Frontend because files already exist. Please run with "--build" to force a rebuild'
@@ -372,27 +357,25 @@ function start_process() {
372
357
373
358
# Assumes the following are set
374
359
# SCRIPT_DIR = The path to the platform_scripts
375
- # NPM = The npm command path
376
360
function build_wilbur() {
377
361
if [ ! -d " ${SCRIPT_DIR} /../../dist" ] || [ " $BUILD_WILBUR " == " 1" ] ; then
378
362
pushd " ${SCRIPT_DIR} /../.." > /dev/null
379
363
echo Building wilbur
380
- " ${NPM} " run build
364
+ npm run build
381
365
popd > /dev/null
382
366
fi
383
367
}
384
368
385
369
# Assumes the following are set
386
370
# SCRIPT_DIR = The path to the platform_scripts
387
- # NPM = The npm command path
388
371
# SERVER_ARGS The arguments to be passed to the server
389
372
function start_wilbur() {
390
373
pushd " ${SCRIPT_DIR} /../../../SignallingWebServer" > /dev/null
391
374
392
375
echo " Starting wilbur signalling server use ctrl-c to exit"
393
376
echo " ----------------------------------"
394
377
395
- start_process " sudo PATH= \" $PATH \" \" $NPM \" start -- ${SERVER_ARGS} "
378
+ start_process " sudo env \" PATH= $PATH \" npm start -- ${SERVER_ARGS} "
396
379
397
380
popd > /dev/null
398
381
}
0 commit comments