-
Notifications
You must be signed in to change notification settings - Fork 202
/
rename-project
executable file
·99 lines (74 loc) · 2.64 KB
/
rename-project
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
#!/usr/bin/env bash
set -eo pipefail
APP_NAME="${1}"
MODULE_NAME="${2}"
FIND_APP_NAME="hello"
FIND_MODULE_NAME="Hello"
FIND_FRAMEWORK="rails"
if [ -z "${APP_NAME}" ] || [ -z "${MODULE_NAME}" ]; then
echo "You must supply both an app and module name, example: ${0} myapp MyApp"
exit 1
fi
if [ "${APP_NAME}" = "${FIND_APP_NAME}" ]; then
echo "Your new app name must be different than the current app name"
exit 1
fi
cat << EOF
When renaming your project you'll need to re-create a new database.
This can easily be done with Docker, but before this script does it
please agree that it's ok for this script to delete your current
project's database(s) by removing any associated Docker volumes.
EOF
while true; do
read -p "Run docker compose down -v (y/n)? " -r yn
case "${yn}" in
[Yy]* )
printf "\n--------------------------------------------------------\n"
docker compose down -v
printf -- "--------------------------------------------------------\n"
break;;
[Nn]* ) exit;;
* ) echo "";;
esac
done
# -----------------------------------------------------------------------------
# The core of the script.
# -----------------------------------------------------------------------------
find . -type f -exec \
perl -i \
-pe "s/(${FIND_APP_NAME}${FIND_FRAMEWORK}|${FIND_APP_NAME})/${APP_NAME}/g;" \
-pe "s/${FIND_MODULE_NAME}/${MODULE_NAME}/g;" {} +
find tmp/ -mindepth 1 ! -name ".keep" -delete
# -----------------------------------------------------------------------------
cat << EOF
--------------------------------------------------------
Your project has been renamed successfully!
--------------------------------------------------------
EOF
function init_git_repo {
[ -d .git/ ] && rm -rf .git/
cat << EOF
--------------------------------------------------------
$(git init)
--------------------------------------------------------
EOF
git symbolic-ref HEAD refs/heads/main
}
while true; do
read -p "Do you want to init a new local git repo (y/n)? " -r yn
case "${yn}" in
[Yy]* ) init_git_repo; break;;
[Nn]* ) break;;
* ) echo "";;
esac
done
cat << EOF
We're done here. Everything worked!
If you're happy with your new project's name you can delete this
script by running: rm bin/rename-project
Or you can keep it around in case you decide to change your project's
name later on after developing it for a bit. You can re-run this
script as many times as you want until you're happy.
Check out the rest of the README on GitHub to wrap things up:
https://github.com/nickjj/docker-${FIND_FRAMEWORK}-example#start-and-setup-the-project
EOF