forked from welldsagl/create-white-label-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwl-generate.sh
executable file
·191 lines (138 loc) · 6.21 KB
/
wl-generate.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
#!/bin/bash
# ------------------------------------------------------------------------------
# VARIABLES
# ------------------------------------------------------------------------------
unset WL_APP_NAME
unset WL_BUNDLE_ID
unset WL_DISPLAY_NAME
unset WL_MODULES
unset WL_THEME
unset WL_DIR_NAME
# ------------------------------------------------------------------------------
# PRINT HELP
# ------------------------------------------------------------------------------
help() {
echo "
Usage: ./wl-generate.sh [flags]
Example: ./wl-generate.sh -a test -b com.test -d Test -m Foo,Bar -t solarized-dark
Description:
This utility generates a configured project \"app-<app-name>\" from \"whitelabel\".
The new project features custom bundle id and display name.
Flags:
-h
Print help.
-a [app-name]
Name of the target application to generate. Has to be different from
'whitelabel'. The directory \"app-<app-name>\" will be generated.
-b [bundle-id]
Bundle identifier for the app.
-d [display-name]
Display name of the app, appearing under the app icon on devices.
-m [module1,module2,...,moduleN]
List of modules to be used in the app, separated by commas (','). At
least one must be provided.
-t [theme]
Name of the theme to be used in the app.
"
}
# ------------------------------------------------------------------------------
# UTILS
# ------------------------------------------------------------------------------
replace_string_in_files() {
local STR_SRC=$1
local STR_DEST=$2
local FILES="${@:3}"
for file in $FILES; do
sed -i '' -e "s/${STR_SRC}/${STR_DEST}/g" $file
done
}
# ------------------------------------------------------------------------------
# PARSE ARGUMENTS
# ------------------------------------------------------------------------------
# If help (-h) found, print help and interrupt script
while getopts ':ha:b:d:m:t:' arg; do
case $arg in
h) help && exit 0 ;;
a) WL_APP_NAME=$OPTARG ;;
b) WL_BUNDLE_ID=$OPTARG ;;
d) WL_DISPLAY_NAME=$OPTARG ;;
m) WL_MODULES=$OPTARG ;;
t) WL_THEME=$OPTARG ;;
esac
done
WL_DIR_NAME="app-${WL_APP_NAME}"
# ------------------------------------------------------------------------------
# WRONG ARGUMENT ERRORS
# ------------------------------------------------------------------------------
# Check app name is not 'whitelabel'
if [ "$WL_APP_NAME" == "whitelabel" ]; then
echo "ERROR: Provided invalid app name 'whitelabel'"
exit 0
fi
# Missing mandatory parameters
if [ -z "$WL_APP_NAME" ]; then echo ERROR: No app name provided; exit 0; fi
if [ -z "$WL_BUNDLE_ID" ]; then echo ERROR: No bundle id provided; exit 0; fi
if [ -z "$WL_DISPLAY_NAME" ]; then echo ERROR: No display anme provided; exit 0; fi
if [ -z "$WL_MODULES" ]; then echo ERROR: No modules provided; exit 0; fi
if [ -z "$WL_THEME" ]; then echo ERROR: No theme provided; exit 0; fi
# ------------------------------------------------------------------------------
# 1. COPY WHITELABEL DIRECTORY
# ------------------------------------------------------------------------------
echo "> Copy 'whitelabel' directory to '${WL_APP_NAME}'"
# Remove previous app directory
if [ -d "./${WL_DIR_NAME}" ]; then
rm -rf "./${WL_DIR_NAME}"
fi
# Copy content of whitelabel into new application directory (files excluded from
# .gitignore will not be copied).
rsync \
-r \
--exclude-from=./whitelabel/.gitignore \
./whitelabel/ \
./${WL_DIR_NAME}
# ------------------------------------------------------------------------------
# 2. CONFIGURE APPLICATION
# ------------------------------------------------------------------------------
./wl-configure.sh \
-a $WL_APP_NAME \
-m $WL_MODULES \
-t $WL_THEME
# ------------------------------------------------------------------------------
# 3. CONFIGURE DISPLAY NAME
# ------------------------------------------------------------------------------
echo "> Set display name '${WL_DISPLAY_NAME}'"
# Replace 'whitelabel' with given display name
replace_string_in_files whitelabel "$WL_DISPLAY_NAME" \
"./${WL_DIR_NAME}/android/app/src/main/res/values/strings.xml" \
"./${WL_DIR_NAME}/ios/whitelabel/Info.plist"
# ------------------------------------------------------------------------------
# 4. CONFIGURE BUNDLE ID
# ------------------------------------------------------------------------------
echo "> Set bundle id '${WL_BUNDLE_ID}'"
# Replace 'com.whitelabel' with given bundle id
replace_string_in_files "com.whitelabel" "$WL_BUNDLE_ID" \
"${WL_DIR_NAME}/android/app/BUCK" \
"${WL_DIR_NAME}/android/app/build.gradle" \
"${WL_DIR_NAME}/android/app/src/main/AndroidManifest.xml" \
"${WL_DIR_NAME}/android/app/src/main/java/com/whitelabel/MainActivity.java" \
"${WL_DIR_NAME}/android/app/src/main/java/com/whitelabel/MainApplication.java" \
"${WL_DIR_NAME}/ios/whitelabel.xcodeproj/project.pbxproj"
# Replace '.' with '/' to get bundle path
# E.g., 'com.whitelabel' -> 'com/whitelabel'
WL_BUNDLE_PATH="${WL_BUNDLE_ID//.//}"
# Create directories for Android java files following new bundle id structure
mkdir -p "./${WL_DIR_NAME}/android/app/src/main/java/${WL_BUNDLE_PATH}/"
# Copy MainApplication and MainActivity to new directories
mv "./${WL_DIR_NAME}/android/app/src/main/java/com/whitelabel/MainActivity.java" \
"./${WL_DIR_NAME}/android/app/src/main/java/${WL_BUNDLE_PATH}/MainActivity.java"
mv "./${WL_DIR_NAME}/android/app/src/main/java/com/whitelabel/MainApplication.java" \
"./${WL_DIR_NAME}/android/app/src/main/java/${WL_BUNDLE_PATH}/MainApplication.java"
# Remove old directory com/whitelabel
rm -d "./${WL_DIR_NAME}/android/app/src/main/java/com/whitelabel/"
# ------------------------------------------------------------------------------
# 5. INSTALL DEPENDENCIES
# ------------------------------------------------------------------------------
echo "> Install dependencies"
pushd "./${WL_DIR_NAME}" > /dev/null
yarn install --silent > /dev/null 2> /dev/null
popd > /dev/null