-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathrun
More file actions
executable file
·128 lines (109 loc) · 2.3 KB
/
Copy pathrun
File metadata and controls
executable file
·128 lines (109 loc) · 2.3 KB
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
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_DIR="${SCRIPT_DIR}/src/ui/flutter_app"
print_usage() {
cat <<'USAGE'
Usage:
./run [desktop|android|ios|linux|macos|windows] [-init]
Examples:
./run
./run android
./run ios
./run -init
./run android -init
USAGE
}
detect_desktop_device() {
local system
system="$(uname -s 2>/dev/null || echo unknown)"
case "${system}" in
Linux*)
printf 'linux\n'
;;
Darwin*)
printf 'macos\n'
;;
MINGW*|MSYS*|CYGWIN*)
printf 'windows\n'
;;
*)
echo "Unsupported desktop environment: ${system}" >&2
return 1
;;
esac
}
resolve_device() {
local target="$1"
case "${target}" in
desktop)
detect_desktop_device
;;
android|ios|linux|macos|windows)
printf '%s\n' "${target}"
;;
*)
echo "Unsupported run target: ${target}" >&2
return 1
;;
esac
}
run_init=false
target="desktop"
target_set=false
while [[ $# -gt 0 ]]; do
case "$1" in
-init|--init)
run_init=true
;;
-h|--help)
print_usage
exit 0
;;
desktop|android|ios|linux|macos|windows)
if [[ "${target_set}" == true ]]; then
echo "Only one run target may be specified." >&2
print_usage >&2
exit 2
fi
target="$1"
target_set=true
;;
*)
echo "Unknown argument: $1" >&2
print_usage >&2
exit 2
;;
esac
shift
done
if [[ ! -d "${APP_DIR}" ]]; then
echo "Flutter app directory does not exist: ${APP_DIR}" >&2
exit 1
fi
if [[ "${run_init}" == true ]]; then
"${SCRIPT_DIR}/flutter-init.sh"
fi
# shellcheck source=scripts/ensure_flutter.sh
source "${SCRIPT_DIR}/scripts/ensure_flutter.sh"
ensure_flutter_on_path
device="$(resolve_device "${target}")"
echo "[run] Target: ${target} (${device})"
run_flutter() {
(cd "${APP_DIR}" && flutter run -d "${device}")
}
if run_flutter; then
exit 0
fi
status="$?"
if [[ "${run_init}" == true ]]; then
exit "${status}"
fi
if [[ "${status}" -ge 128 ]]; then
exit "${status}"
fi
echo "[run] Flutter run failed with exit code ${status}." >&2
echo "[run] Running ./flutter-init.sh once, then retrying flutter run." >&2
"${SCRIPT_DIR}/flutter-init.sh"
echo "[run] Retrying target: ${target} (${device})"
run_flutter