-
Notifications
You must be signed in to change notification settings - Fork 6
/
bootstrap.sh
executable file
·199 lines (157 loc) · 4.48 KB
/
bootstrap.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
#!/bin/bash
unset newName
while [ -z "$newName" ]; do
read -p "Please provide a new project name (My Project): " newName
done
unset newBundle
while [ -z "$newBundle" ]; do
read -p "Please provide a new bundle identifier (digital.wisemen.My-Project): " newBundle
done
unset newTeamID
while [ -z "$newTeamID" ]; do
read -p "Please provide a new Apple Team ID (XXXXXXXXXX): " newTeamID
done
unset appleID
while [ -z "$appleID" ]; do
read -p "Please provide your Apple ID ([email protected]): " appleID
done
unset newSentryProject
while [ -z "$newSentryProject" ]; do
read -p "Please provide your Sentry Project slug (my-project-ios): " newSentryProject
done
unset newSentryDSN
while [ -z "$newSentryDSN" ]; do
read -p "Please provide your Sentry DSN (https://<key>@sentry.appwi.se/<project>): " newSentryDSN
done
unset sentryToken
while [ -z "$sentryToken" ]; do
read -p "Please provide your Sentry OAuth Token: " sentryToken
done
#### Steps ####
function fixPodfile {
echo "Fixing Podfile..."
# remove local pod path
sed -i '' -e "s#, :path => '\.\./'#, '~> 2.0'#g" Podfile
}
function fixProjectfile {
echo "Fixing project file..."
# project template files
sed -i '' \
-e "s#\.\./XcodeGen#Pods/AppwiseCore/XcodeGen#g" \
-e "s#3JQPC5UP5E#$newTeamID#g" \
project.yml
}
function fixFastfile {
echo "Fixing Fastfile..."
# point scripts to right path
sed -i '' -e "s#\.\./Fastlane Actions#Pods/AppwiseCore/Fastlane Actions#g" fastlane/Fastfile
}
function fixSourcery {
echo "Fixing Sourcery..."
# template files
sed -i '' -e "s#\.\./Sourcery#Pods/AppwiseCore/Sourcery#g" .sourcery.yml
}
function fixSwiftGen {
echo "Fixing SwiftGen..."
# template files
sed -i '' -e "s#\.\./SwiftGen#Pods/AppwiseCore/SwiftGen#g" swiftgen.yml
}
# move files to new locations, we handle up to 2 levels deep of renaming
function relocateFiles {
echo "Moving files..."
find . -path "$podsDir" -prune -o -name "*${oldName}*" -print0 | while IFS= read -r -d '' file; do
target="${file/$oldName/$newName}"
if [[ $target = *"$oldName"* ]]; then
# already moved the parent
deeperTarget="${target/$oldName/$newName}"
mv "$target" "$deeperTarget"
else
mv "$file" "$target"
fi
done
}
function replaceText {
echo "Replacing '$1' with '$2'..."
grep -rl --null "$1" --exclude-dir=".git" --exclude-dir="$podsDir" --exclude="bootstrap.sh" . | LC_CTYPE=C LANG=C xargs -0 sed -i '' "s#$1#$2#g"
}
function configureFastlane {
echo "Creating Fastlane environment file..."
cat >.env <<EOL
# Your Apple email address
USER_APPLE_ID=$appleID
# Sentry configuration
SENTRY_AUTH_TOKEN=$sentryToken
EOL
}
function podUpdate {
command -v bundle >/dev/null 2>&1 || { echo >&2 "I require Bundler but it's not installed. Aborting."; exit 1; }
echo "Installing gems..."
bundle update >/dev/null
echo "Installing pods..."
bundle exec pod update >/dev/null
}
function cleanup {
echo "Cleaning up..."
rm -f "CHANGELOG.md"
rm -f "LICENSE"
rm -f "README.md"
rm -f "bootstrap.sh"
}
function initializeGit {
echo "Initializing Git..."
rm -rf ".git"
git init >/dev/null
git checkout -b "main" >/dev/null
git add "*" >/dev/null
echo "Creating initial commit."
git commit -m "Initial commit" >/dev/null
echo "Adding commit hooks..."
swift run komondor install >/dev/null
echo "Creating branches."
git branch "staging"
git branch "development"
git checkout "development"
}
#### Start of flow ####
# constants
podsDir="./Pods"
oldName="Example Project"
oldModuleName="Example_Project"
oldTeamID="XXXXXXXXXX"
oldBundle="be.appwise.Example-Project"
oldSentryProject="example-project-ios"
oldSentryDSN="https://<key>@sentry.io/<project>"
newModuleName=${newName// /_}
if [[ $newModuleName =~ ^[0-9] ]]; then
newModuleName="_${newModuleName:1}"
fi
echo "Bootstrapping project:
- Target: $newName
- Module: $newModuleName
- Bundle: $newBundle
- Apple Team: $newTeamID
- Apple ID: $appleID
- Sentry Project slug: $newSentryProject
- Sentry DSN: $newSentryDSN
- Sentry OAuth Token: $sentryToken"
read -rsn1 -p "Press any key to continue";echo
fixPodfile
fixFastfile
fixProjectfile
fixSourcery
fixSwiftGen
relocateFiles
# replace name in files
replaceText "$oldName" "$newName"
replaceText "$oldModuleName" "$newModuleName"
replaceText "$oldTeamID" "$newTeamID"
replaceText "$oldBundle" "$newBundle"
replaceText "$oldSentryProject" "$newSentryProject"
replaceText "$oldSentryDSN" "$newSentryDSN"
configureFastlane
podUpdate
cleanup
initializeGit
echo "
Done!
"