-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_device.sh
executable file
·131 lines (115 loc) · 2.79 KB
/
run_device.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
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
#!/usr/bin/env bash
#
# Example taken from http://argbash.readthedocs.io/en/stable/example.html
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export VERSION_NUMBER=1.3.1
export ENABLE_LOGS=true
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options
all_short_options='pdeh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_platform=ios
_arg_device=''
_arg_environment=local
print_help ()
{
printf "%s\n" "The general script's help msg"
printf 'Usage: %s [-p|--platform <arg>] [-d|--device <arg>] [-e|--environment <arg>] [-h|--help]\n' "$0"
printf "\t%s\n" "-p,--platform: the platform to target 'android | ios | web'. default: ios"
printf "\t%s\n" "-d,--device: the platform to target 'emulator | device'. default: none"
printf "\t%s\n" "-e,--environment: the environment to target. default: local"
printf "\t%s\n" "-h,--help: Prints help"
}
parse_commandline ()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
-p|--platform)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_platform="$2"
shift
;;
--platform=*)
_arg_platform="${_key##--platform=}"
;;
-p*)
_arg_platform="${_key##-p}"
;;
-d|--device)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_device="$2"
shift
;;
--device=*)
_arg_device="${_key##--device=}"
;;
-d*)
_arg_device="${_key##-d}"
;;
-e|--environment)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_environment="$2"
shift
;;
--environment=*)
_arg_environment="${_key##--environment=}"
;;
-e*)
_arg_environment="${_key##-e}"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
echo "Value of --platform: $_arg_platform"
echo "Value of --device: $_arg_device"
echo "Value of --environment: $_arg_environment"
function run_device() {
cd "$DIR"/mywell-ui/
PATH=$(npm bin):$PATH
npm run build:"$_arg_environment"
ionic run $_arg_platform --"$_arg_device"
}
function run_web() {
cd "$DIR"/mywell-ui/
echo "WARNING: run_device -d web currently only supports webpack dev server"
source "$DIR"/env/env"$_arg_environment".sh
npm run webpack_dev_server
}
case "$_arg_platform" in
ios|android)
run_device
;;
web)
run_web
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Device must be one of android | ios | web. Got: '$1'" 1
;;
esac