forked from GitJournal/GitJournal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flutterw
executable file
·112 lines (97 loc) · 4.19 KB
/
flutterw
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
#!/usr/bin/env sh
# SPDX-FileCopyrightText: 2021 Vishesh Handa <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0
##############################################################################
##
## Flutter start up script for UN*X
## Version: v1.1.2
## Date: 2021-03-09 13:41:00
##
## Use this flutter wrapper to bundle Flutter within your project to make
## sure everybody builds with the same version.
##
## Read about the install and uninstall process in the README on GitHub
## https://github.com/passsy/flutter_wrapper
##
## Inspired by gradle-wrapper.
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ]; do
ls=$(ls -ld "$PRG")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' >/dev/null; then
PRG="$link"
else
PRG=$(dirname "$PRG")"/$link"
fi
done
SAVED="$(pwd)"
cd "$(dirname "$PRG")/" >/dev/null
APP_HOME="$(pwd -P)"
cd "$SAVED" >/dev/null
FLUTTER_SUBMODULE_NAME='.flutter'
FLUTTER_DIR="$APP_HOME/$FLUTTER_SUBMODULE_NAME"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
# submodule starting with "-" are not initialized
init_status=$(git submodule | grep "\ $FLUTTER_SUBMODULE_NAME$" | cut -c 1)
# Fix not initialized flutter submodule
if [ "$init_status" = "-" ]; then
echo "$FLUTTER_SUBMODULE_NAME submodule not initialized. Initializing..."
git submodule update --init ${FLUTTER_SUBMODULE_NAME}
fi
# Detect detach HEAD and fix it. commands like upgrade expect a valid branch, not a detached HEAD
FLUTTER_SYMBOLIC_REF=$(git -C ${FLUTTER_SUBMODULE_NAME} symbolic-ref -q HEAD)
if [ -z ${FLUTTER_SYMBOLIC_REF} ]; then
FLUTTER_REV=$(git -C ${FLUTTER_SUBMODULE_NAME} rev-parse HEAD)
FLUTTER_CHANNEL=$(git config -f .gitmodules submodule.${FLUTTER_SUBMODULE_NAME}.branch)
if [ -z $FLUTTER_CHANNEL ]; then
echo "Warning: Submodule '$FLUTTER_SUBMODULE_NAME' doesn't point to an official Flutter channel \
(one of stable|beta|dev|master). './flutterw upgrade' will fail without a channel."
echo "Fix this by adding a specific channel with:"
echo "\t- './flutterw channel <channel>' or"
echo "\t- Add 'branch = <channel>' to '$FLUTTER_SUBMODULE_NAME' submodule in .gitmodules"
else
echo "Fixing detached HEAD: '$FLUTTER_SUBMODULE_NAME' submodule points to a specific commit $FLUTTER_REV, not channel '$FLUTTER_CHANNEL' (as defined in .gitmodules)."
# Make sure channel is fetched
# Remove old channel branch because it might be moved to an unrelated commit where fast-forward pull isn't possible
git -C ${FLUTTER_SUBMODULE_NAME} branch -q -D ${FLUTTER_CHANNEL} 2> /dev/null || true
git -C ${FLUTTER_SUBMODULE_NAME} fetch -q origin
# bind current HEAD to channel defined in .gitmodules
git -C ${FLUTTER_SUBMODULE_NAME} checkout -q -b ${FLUTTER_CHANNEL} ${FLUTTER_REV}
git -C ${FLUTTER_SUBMODULE_NAME} branch -q -u origin/${FLUTTER_CHANNEL} ${FLUTTER_CHANNEL}
echo "Fixed! Migrated to channel '$FLUTTER_CHANNEL' while staying at commit $FLUTTER_REV. './flutterw upgrade' now works without problems!"
git -C ${FLUTTER_SUBMODULE_NAME} status -bs
fi
fi
# Wrapper tasks done, call flutter binay with all args
set -e
"$FLUTTER_DIR/bin/flutter" "$@"
# Post flutterw tasks. exit code from /bin/flutterw will be used as final exit
FLUTTER_EXIT_STATUS=$?
if [ ${FLUTTER_EXIT_STATUS} -eq 0 ]; then
# ./flutterw channel CHANNEL
if echo "$@" | grep -q "channel"; then
# make sure .gitmodules is updated as well
CHANNEL=${2} # second arg
git config -f .gitmodules submodule.${FLUTTER_SUBMODULE_NAME}.branch ${CHANNEL}
# makes sure nobody forgets to do commit all changed files
git add .gitmodules
git add ${FLUTTER_SUBMODULE_NAME}
fi
# ./flutterw upgrade
if echo "$@" | grep -q "upgrade"; then
# makes sure nobody forgets to do commit the changed submodule
git add ${FLUTTER_SUBMODULE_NAME}
# flutter packages get runs automatically. Stage those changes as well
git add pubspec.lock
fi
fi
exit ${FLUTTER_EXIT_STATUS}