generated from nimblehq/git-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.sh
executable file
·133 lines (114 loc) · 3.43 KB
/
make.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
#!/bin/sh
set -e
# Script inspired by https://gist.github.com/szeidner/613fe4652fc86f083cefa21879d5522b
readonly PROGNAME=$(basename $0)
readonly WORKING_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
die() {
echo "$PROGNAME: $*" >&2
exit 1
}
usage() {
if [ "$*" != "" ] ; then
echo "Error: $*"
fi
cat << EOF
Usage: $PROGNAME --bundle-id [BUNDLE_ID_PRODUCTION] --bundle-id-staging [BUNDLE_ID_STAGING] --project-name [PROJECT_NAME]
Set up an iOS app from tuist template.
Options:
-h, --help display this usage message and exit
-b, --bundle-id [BUNDLE_ID_PRODUCTION] the production id (i.e. com.example.package)
-s, --bundle-id-staging [BUNDLE_ID_STAGING] the staging id (i.e. com.example.package.staging)
-n, --project-name [PROJECT_NAME] the project name (i.e. MyApp)
EOF
exit 1
}
bundle_id_production=""
bundle_id_staging=""
project_name=""
minimum_ios_version=""
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help)
usage
;;
-b|--bundle-id)
bundle_id_production="$2"
shift
;;
-s|--bundle-id-staging)
bundle_id_staging="$2"
shift
;;
-n|--project-name)
project_name="$2"
shift
;;
-iv|--ios-version)
minimum_ios_version="$2"
shift
;;
-*)
usage "Unknown option '$1'"
;;
*)
usage "Too many arguments"
;;
esac
shift
done
if [ -z "$bundle_id_production" ] ; then
read -p "BUNDLE ID PRODUCTION (i.e. com.example.project):" bundle_id_production
fi
if [ -z "$bundle_id_staging" ] ; then
read -p "BUNDLE ID STAGING (i.e. com.example.project.staging):" bundle_id_staging
fi
if [ -z "$bundle_id_production" ] || [ -z "$bundle_id_staging" ] ; then
usage "Input cannot be blank."
fi
# Enforce package name
regex='^[a-z][a-z0-9_]*(\.[a-z0-9_-]+)+[0-9a-z_-]$'
if ! [[ $bundle_id_production =~ $regex ]]; then
die "Invalid Package Name: $bundle_id_production (needs to follow standard pattern {com.example.package})"
fi
if [ -z "$project_name" ] ; then
read -p "PROJECT NAME (i.e. NewProject):" project_name
fi
if [[ -z "$minimum_ios_version" ]]; then
read -p "iOS Minimum Version (i.e. 14.0):" minimum_ios_version
fi
# Enforce minimum version
version_regex='^[0-9_]+(\.[0-9]+)+$'
if ! [[ $minimum_ios_version =~ $version_regex ]]; then
echo "=> Minimum version incorrect. Reverting to default version."
minimum_ios_version="14.0"
fi
# Reset all git submodules changes
cd ios
git add .
git reset --hard
cd ..
cd android
git add .
git reset --hard
cd ..
# Generate iOS module
sh scripts/make_ios.sh -b ${bundle_id_production} -s ${bundle_id_staging} -n ${project_name} -iv ${minimum_ios_version}
# Generate Android module
sh scripts/make_android.sh -b ${bundle_id_production} -n ${project_name}
# Clone all project files to the $project_name directory
echo "=> Clone all project files to the '$project_name' directory"
rsync -av \
--exclude '.git' \
--exclude '.gitmodules' \
--exclude 'make.sh' \
--exclude 'CONTRIBUTING.md' \
--exclude '/scripts' \
--exclude '/custom' \
--exclude '/android' \
--exclude '/shared' \
--exclude '/sample' \
--exclude '/'$project_name \
./ $project_name/
rsync -av ./android/$project_name/app/ $project_name/android/
# Generate Shared module
kscript scripts/make_shared.kts package-name=${bundle_id_production} app-name=${project_name}