forked from wisemen-digital/AppwiseCore-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·112 lines (88 loc) · 2.55 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
#!/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 (be.appwise.My-Project): " newBundle
done
unset appleID
while [ -z "$appleID" ]; do
read -p "Please provide your Apple ID ([email protected]): " appleID
done
#### Steps ####
function deintegratePods {
command -v pod >/dev/null 2>&1 || { echo >&2 "I require CocoaPods but it's not installed. Aborting."; exit 1; }
echo "Deintegrating pods..."
pod deintegrate >/dev/null
}
function fixPodfile {
echo "Fixing Podfile..."
sed -i.bak -e "s/, :path => '\.\.\/'//g" Podfile && rm Podfile.bak
sed -i.bak -e "s/\\\"\.\.\//\\\"\\\${PODS_ROOT}\/AppwiseCore\//g" Podfile && rm Podfile.bak
}
# 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="$podsDir" --exclude="rename.sh" . | 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
EOL
}
function podInstall {
command -v pod >/dev/null 2>&1 || { echo >&2 "I require CocoaPods but it's not installed. Aborting."; exit 1; }
echo "Installing pods..."
pod install >/dev/null
}
function cleanup {
echo "Cleaning up..."
rm -f "CHANGELOG.md"
rm -f "LICENSE"
rm -f "README.md"
rm -f "bootstrap.sh"
}
#### Start of flow ####
# constants
podsDir="./Pods"
oldName="Example Project"
oldModuleName="Example_Project"
oldBundle="be.appwise.Example-Project"
newModuleName=${newName// /_}
if [[ $newModuleName =~ ^[0-9] ]]; then
newModuleName="_${newModuleName:1}"
fi
echo "Bootstrapping project:"
echo "- Target: $newName"
echo "- Module: $newModuleName"
echo "- Bundle: $newBundle"
echo "- Apple ID: $appleID"
read -rsn1 -p "Press any key to continue";echo
deintegratePods
fixPodfile
relocateFiles
# replace name in files
replaceText "$oldName" "$newName"
replaceText "$oldModuleName" "$newModuleName"
replaceText "$oldBundle" "$newBundle"
configureFastlane
podInstall
cleanup
echo "Done!"