-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcordova.sh
executable file
·212 lines (184 loc) · 5.49 KB
/
cordova.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
GREEN='\033[0;32m';
YELLOW='\033[1;33m';
CYAN='\033[0;36m';
NC='\033[0m'; # No Color
BORDER=$(printf '=%.0s' {1..42});
cordova_title=$( echo;echo;printf ${NC}$BORDER;printf "\n\tCordova Setup\n";echo $BORDER; echo )
cordova_description=$( printf "\n\nPlease make sure you have Android Studio and XCode installed\n" )
cordovaopts=(
"Setup Android and iOS"
"Setup Android"
"Setup iOS"
"Exit Cordova Setup"
)
androidopts=(
"Development"
"Release"
"Exit"
)
os_opts=(
"Mac OS X"
"Linux"
"Windows"
)
platforms=(
"Android"
"iOS"
"Exit"
)
prompt=$(printf "\nPick an option and press [enter]: ")
shopt -s extglob
cordova_init(){
echo
printf "${YELLOW}Please enter your new project directory name:${NC} "
read dirname
echo
printf "${YELLOW}Please enter your app id (e.g. com.company.projectname):${NC} "
read projectname
echo
printf "${YELLOW}Please enter your app's display title (i.e. ProjectName):${NC} "
read displayname
cordova create $dirname $projectname $displayname
cp -r !($dirname|*.png) $dirname/www/
cp *.png $dirname/
rm -rf $dirname/res
cd $dirname
mkdir hooks/after_prepare
touch hooks/after_prepare/cordova-icon.sh
chmod +x hooks/after_prepare/cordova-icon.sh
cat > hooks/after_prepare/cordova-icon.sh << EOF
#!/bin/bash
if cordova-icon ; then
echo "Icons built successfully"
else
printf "cordova-icon build failed.\nPlease install the follow the instructions here to install cordova-icon: https://github.com/AlexDisler/cordova-icon"
fi
EOF
touch hooks/after_prepare/cordova-splash.sh
chmod +x hooks/after_prepare/cordova-splash.sh
cat > hooks/after_prepare/cordova-splash.sh << EOF
#!/bin/bash
if cordova-splash ; then
echo "Splash images built successfully"
else
printf "cordova-splash build failed.\nPlease install the follow the instructions here to install cordova-splash: https://github.com/AlexDisler/cordova-splash"
fi
EOF
cordova_setup
}
cordova_setup(){
echo
clear
printf "${CYAN}${cordova_title}${NC}"
printf "${YELLOW}${cordova_description}${NC}\n\n"
PS3="$prompt"
select opt in "${cordovaopts[@]}"; do
case "$REPLY" in
1 ) init_android_and_ios; break;;
2 ) init_android; break;;
3 ) init_ios; break;;
4 ) break;;
*) echo "Invalid option. Please enter 1, 2, 3, or 4.";continue;;
esac
done
}
# cordova version needed for CLI
# https://stackoverflow.com/questions/42668185/could-not-find-gradle-wrapper-within-android-sdk-might-need-to-update-your-andr
init_android_and_ios(){
echo
cordova platform rm android ios
cordova platform add android@6.2.2
cordova platform add ios
android_environment_menu
launch_xcode
}
init_android(){
echo
cordova platform rm android
cordova platform add android@6.2.2
android_environment_menu
}
android_environment_menu(){
echo
printf "\n${BORDER}\n\n${CYAN}Would you like to build for android for development or release?${NC}\n\n"
PS3="$prompt"
select opt in "${androidopts[@]}"; do
case "$REPLY" in
1 ) setup_android_development; break;;
2 ) setup_android_release; break;;
3 ) break;;
*) echo "Invalid option. Please enter 1, 2, or 3.";continue;;
esac
done
}
init_ios(){
echo
cordova platform rm ios
cordova platform add ios
launch_xcode
}
launch_xcode(){
echo
open platforms/ios/$displayname.xcodeproj
if [ $? -eq 0 ]; then
echo;echo
printf "Welcome to ${displayname} App iOS"
printf "${BORDER}\nPlease do your development and release builds inside of XCode\n"
echo
echo "XCode instructions: "
echo
echo "First time:"
printf "\n\t- On the top menu bar click Xcode > Preferences > Accounts"
printf "\n\t- Login to your account"
printf "\n\t- Click on your account, and in the details section click 'Download all profiles'"
echo "- Choose your device"
echo "- Assign the signing team to your profile"
echo "- Hit the play button to run the app in development"
echo
else
echo 'Something went wrong. Please check your logs.'
echo 'Please make sure that XCode is installed and that you have valid signing certificates'
echo;echo
fi
}
setup_android_development(){
echo
cordova run android # cordova run dev build
if [ $? -eq 0 ]; then
echo;echo
echo 'Welcome to your android app'
echo;echo
else
echo 'Something went wrong. Please check your logs.'
echo 'It might be that you have no android device attached or that you do not have an android emulator installed.'
printf "run adb devices to make sure you have an authorized device attached, or install an android emulator from Android studio."
echo;echo
fi
}
setup_android_release(){
echo
read -p "Have you updated the version number in 'config.xml' and 'package.json'? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
cordova build android --release # build android release apk file
if [ $? -eq 0 ]; then
printf "${GREEN}Release apk has been built.${NC}\n\n"
echo "Please the new release apk in platforms/build/outputs/apk/android-release.apk to the Google Play Store\n"
echo;echo;
else
echo 'Something went wrong. Please check your logs.'
echo 'It might be that you have no android device attached or that you do not have an android emulator installed.'
printf "run ${CYAN}adb devices${NC} to make sure you have an authorized device attached, or install an android emulator from Android studio."
echo
fi
else
printf "Please update the version number in ${YELLOW}config.xml${NC} and ${YELLOW}package.json${NC}\n"
echo "Afterwards, do ${CYAN}npm run cordova-android-release${NC} to return to this menu."
fi
}
clear
echo;echo
printf "${CYAN}Welcome to Cordova App Builder${NC}";echo;echo
cordova_init