generated from CleanCut/bevy_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·151 lines (136 loc) · 5.53 KB
/
setup
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
#!/usr/bin/env bash
function ask_yn() {
read -rp "❓ $1 (Y/n) " answer
if [[ "$answer" == "" || "$answer" == "y" || "$answer" == "Y" || "$answer" == "yes" || "$answer" == "Yes" ]]; then
return 0
else
return 1
fi
}
function result() {
echo "⚡ $1"
}
function info() {
echo "💡 $1"
}
function die() {
echo "🛑 FATAL: $1"
}
function warn() {
echo "⚠️ $1"
}
# --- Set package.name in Cargo.toml ---
name_with_ext=$(git remote show -n origin | grep "Fetch URL" | cut -d / -f 2-)
name="${name_with_ext%.*}"
if grep -q "bevy_template" Cargo.toml; then
if ask_yn "Set the package name to ${name}?"; then
sed -e "s/bevy_template/${name}/" -i "" Cargo.toml || die "Couldn't set the package name to ${name}"
result "Set package name to ${name}"
else
warn "Okay, you should go set the package name in Cargo.toml manually."
fi
else
info "Package name already set."
fi
# --- Set package.authors in Cargo.toml ---
if grep -q "Unknown Author" Cargo.toml; then
DEFAULT_AUTHOR="$(git config --global user.name) <$(git config --global user.email)>"
if ask_yn "Set the author to ${DEFAULT_AUTHOR}?"; then
sed -E -e "s/Unknown Author <[email protected]>/${DEFAULT_AUTHOR}/" -i "" Cargo.toml ||
die "Couldn't set the author."
result "Set author to ${DEFAULT_AUTHOR}"
else
warn "Okay, you should go set the author in Cargo.toml manually."
fi
else
info "Author already set."
fi
# --- Set latest version of Bevy ---
json=$(curl --silent --user-agent "bevy_template (github.com/cleancut/bevy_template)" https://crates.io/api/v1/crates/bevy)
version=$(echo "${json}" | grep -oE '"max_version":".*?"' | cut -d '"' -f 4)
if ! grep -qE "^bevy = \"${version}\"\$" Cargo.toml; then
if ask_yn "Try to update to the latest version of Bevy ($version)? If you have customized the version string, say no here."; then
sed -E -e "s/^bevy = \".*\"\$/bevy = \"${version}\"/" -i "" Cargo.toml || die "Couldn't update Bevy version to ${version}"
result "Updated to version ${version}"
else
warn "Okay, leaving the version alone."
fi
else
info "Bevy is already on the latest version (${version}), skipping version update."
fi
# --- Configure fast-compile ---
if [[ -f .cargo/config_fast_builds ]]; then
if ask_yn "Fast-compile is not configured. Would you like me to set it up now? This involves installing an external linker and using the nightly Rust compiler."; then
mv .cargo/config_fast_builds .cargo/config.toml || die "Failed moving config file into place"
result "Configured fast-compile to use zld/lld linker for debug builds."
else
warn "Okay, not configuring fast-compile."
fi
elif [[ -f .cargo/config ]] && grep -q -- "-Zshare-generics=y" .cargo/config; then
info "Fast-compile is already configured. If you want to disable it, delete or comment out .cargo/config"
fi
if [[ $(uname) == "Darwin" ]]; then
if brew list michaeleisel/zld/zld > /dev/null 2> /dev/null ; then
info "zld is installed"
else
if ask_yn "Install zld? Answer yes if you configured fast-install." ; then
brew install michaeleisel/zld/zld \
|| die "Failed running 'brew install michaeleisel/zld/zld -- do you have brew installed? https://brew.sh/"
result "installed zld"
else
warn "Okay, not installing zld."
fi
fi
else
warn "PLEASE MAKE SURE YOU HAVE LLD INSTALLED! Instructions are available at https://bevyengine.org/learn/book/getting-started/setup/"
fi
# --- Install nightly compiler ---
if rustup toolchain list | grep -q nightly; then
info "Nightly compiler already installed."
else
if ask_yn "No nightly compiler installed. Install it via rustup? Answer 'yes' if you configured fast-compile."; then
rustup install nightly || die "Failed to install nightly compiler. Do you have rustup installed?"
result "Done installing nightly compiler."
else
warn "Okay, not installing nightly compiler."
fi
fi
# --- Configure project to use nightly compiler ---
if rustup toolchain list | grep -q nightly; then
if rustup override list | grep -qE "$(pwd).*nightly"; then
info "Already using nightly compiler for this project."
else
if ask_yn "Configure this project to use the nightly compiler? Answer 'yes' if you configured fast-compile."; then
rustup override set nightly || die "Failed configuring project to use nightly compiler"
result "Configured project to use the nightly compiler."
else
warn "Okay, not configuring project to use the nightly compiler."
fi
fi
else
info "Nightly is not installed, skipping step for configuring project to use nightly."
fi
# --- Replace README.md ---
if [[ -f README.md ]] && grep -q "Bevy Template" README.md; then
if ask_yn "Replace template README.md with a blank one?"; then
echo "# My Project" > README.md || die "Failed replacing README.md"
result "Replaced README.md with blank one."
else
warn "Okay, left template README.md in place."
fi
else
info "README.md has already been replaced"
fi
# --- Delete the license ---
if [[ -f LICENSE ]] && grep -q "Nathan Stocks" LICENSE; then
if ask_yn "Delete the LICENSE file so you can add your own?"; then
rm LICENSE || die "Failed deleting LICENSE file."
result "Deleted the LICENSE file that belonged to the template. Feel free to license your project in whatever way you choose."
else
warn "Okay, left LICENSE alone."
fi
else
info "Template license has already been removed."
fi
# --- Finish Up ---
echo "✅ Finished! Please check the changes and commit. If you want to commit everything, do 'git add -A && git commit -m \"Configured project\"'"