-
Notifications
You must be signed in to change notification settings - Fork 26
/
run-ls
executable file
·53 lines (43 loc) · 1.34 KB
/
run-ls
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
#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
find_scada_root () {
local name=""
testing_dir=$1
while :; do
name=$(basename $testing_dir)
ls "$testing_dir/scada.js" > /dev/null 2>&1
if [[ "$?" == "0" ]]; then
echo "$testing_dir/scada.js"
return 0
elif [[ "$name" == "scada.js" ]]; then
echo $testing_dir
return 0
elif [[ "$name" == "/" ]]; then
return 255
else
testing_dir=$(realpath "$testing_dir/..")
fi
done
}
filename=$1
if [[ ! -f $filename ]]; then
echo "First argument should be a file to run."
exit 255
fi
base_dir=$(dirname $filename)
#echo "DEBUG: Base Dir: $base_dir"
SCADA_DIR=$(find_scada_root $base_dir)
if [[ -d $SCADA_DIR ]]; then
#echo "DEBUG: found scada root: $SCADA_DIR"
SCADA_MODULES="${SCADA_DIR}/lib"
PROJECT_PATH=$(realpath "${SCADA_DIR}/..")
echo "ScadaJS project path: ${PROJECT_PATH}"
FOUND_MODULES=
# add every `node_modules` into the path
while IFS= read -r module; do
#echo "++++++++++ adding path: $module"
FOUND_MODULES="${FOUND_MODULES}:$module"
done < <(find $PROJECT_PATH -type d -name "node_modules" | grep -v "node_modules\/" )
fi
export NODE_PATH="${SCADA_MODULES}:${FOUND_MODULES}:${NODE_PATH}"
lsc $@