-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·64 lines (53 loc) · 1.94 KB
/
setup.sh
File metadata and controls
executable file
·64 lines (53 loc) · 1.94 KB
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
#!/usr/bin/env bash
set -eo pipefail
removeModulePrompt() {
read -p "Do you want to remove the $1 sample (y/n)? " answer
case ${answer:0:1} in
y|Y )
sed -i "/^include(\":$2\")/d" ./settings.gradle.kts
rm -rf ./$2
;;
esac
}
# read project name
echo "This script will set up your new Kotlin project."
read -p "Enter your project name: " projectName
if [[ -z "$projectName" ]]; then
echo "Project name can not be empty"
exit 1
fi
# remove license file if confirmed
read -p "Do you want to remove the license file (y/n)? " answer
case ${answer:0:1} in
y|Y )
rm LICENSE.txt
;;
esac
# remove modules if confirmed
removeModulePrompt "Kotlin library" "kotlin-lib"
removeModulePrompt "Kotlin MPP library" "kotlin-multiplatform-lib"
removeModulePrompt "Kotlin Android library" "kotlin-android-lib"
removeModulePrompt "Kotlin Android app" "kotlin-android-app"
echo "Configuring project '$projectName'..."
# update license if it's not deleted
if [[ -e LICENSE.txt ]]; then
date=$(date +%Y)
gitUser=$(git config --global --get user.name)
awk -v date=$date -v name="$gitUser" '{ gsub(/^ Copyright.*$/," Copyright " date " " name); print }' LICENSE.txt > tmp && mv tmp LICENSE.txt
fi
# change root project name
awk -v name=$projectName '{ gsub(/^rootProject\.name\ =\ [a-zA-Z-"]+$/,"rootProject.name = \"" name "\""); print }' settings.gradle.kts > tmp && mv tmp settings.gradle.kts
awk -v name=$projectName '{ gsub(/^rootProject\.name\ =\ [a-zA-Z-"]+$/,"rootProject.name = \"" name "\""); print }' buildSrc/settings.gradle.kts > tmp && mv tmp buildSrc/settings.gradle.kts
# update readme
rm README.md
echo "# $projectName" >> README.md
# remove renovate config
rm .github/renovate.json5
read -p "Do you want to remove GitHub actions config (y/n)? " answer
case ${answer:0:1} in
y|Y )
rm -rf .github
;;
esac
echo "Project '$projectName' configured. Changes can be committed."
exit 0