-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-helper.sh
executable file
·75 lines (63 loc) · 1.67 KB
/
build-helper.sh
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
#!/usr/bin/env bash
set -o errexit; set -o nounset; set -o pipefail
pushd `dirname $0` > /dev/null
SCRIPT_PATH=`pwd`
popd > /dev/null
function print_help()
{
echo ""
echo "Usage: $0 -c install"
echo -e "\t-c Selected Command"
exit 1 # Exit script after printing help
}
function install_dependencies() {
for i in ./*/package.json;
do
SERVICE_DIRECTORY="$(dirname "${i}")"
printf "Start Installing dependencies on %s\n" "$SERVICE_DIRECTORY" ;
(cd $SERVICE_DIRECTORY && npm i);
done
}
function run_linter() {
for i in ./*/package.json;
do
SERVICE_DIRECTORY="$(dirname "${i}")"
printf "Linting Files on %s\n" "$SERVICE_DIRECTORY" ;
(cd $SERVICE_DIRECTORY && npm run lint:fix);
done
}
function clean_node() {
for i in ./*/package.json;
do
SERVICE_DIRECTORY="$(dirname "${i}")"
printf "Removing %s\n" "$SERVICE_DIRECTORY/node_modules" ;
(cd $SERVICE_DIRECTORY && rm -rf node_modules);
done
}
selected_command=""
while getopts "a:b:c:" opt
do
case "$opt" in
a ) selected_command="$OPTARG" ;;
b ) selected_command="$OPTARG" ;;
c ) selected_command="$OPTARG" ;;
? ) print_help ;; # Print helpFunction in case parameter is non-existent
esac
done
# Print helpFunction in case parameters are empty
if [ -z "$selected_command" ]
then
echo "Some or all of the parameters are empty";
print_help
fi
if [ "${selected_command}" == "install" ]; then
install_dependencies
fi
if [ "${selected_command}" == "lint" ]; then
run_linter
fi
if [ "${selected_command}" == "clean" ]; then
clean_node
fi
# Begin script in case all parameters are correct
echo "$selected_command"