How to rename an Elixir Phoenix app
February 2023 • 114 words • 1 min read
There are times when you want to rename your Phoenix project. It requires renaming the module as well the OTP app. You can use following sequence of steps:
Steps
- Check in all your files into a git repo (
git init .
,git add -A
,git commit -m 'initial commit'
) - Create a new file
rename_phoenix_project.sh
and copy the code. - Replace the variables
NEW_NAME
andNEW_OTP
with the appropriate new names. - Replace the variables
CURRENT_NAME
andCURRENT_OTP
with the old names. - Save the file, and execute the script in the terminal:
sh rename_phoenix_project.sh
#!/bin/bash
export LC_CTYPE=C
export LANG=C
NEW_NAME="NewName"
NEW_OTP="new_name"
CURRENT_NAME="OldName"
CURRENT_OTP="old_name"
set -e
if ! command -v ack &> /dev/null
then
echo "\`ack\` could not be found. Please install it before continuing (Mac: brew install ack)."
exit 1
fi
ack -l $CURRENT_NAME --ignore-file=is:rename_phoenix_project.sh | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g"
ack -l $CURRENT_OTP --ignore-file=is:rename_phoenix_project.sh | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g"
git mv lib/$CURRENT_OTP lib/$NEW_OTP
git mv lib/$CURRENT_OTP.ex lib/$NEW_OTP.ex
git mv lib/${CURRENT_OTP}_web lib/${NEW_OTP}_web
git mv lib/${CURRENT_OTP}_web.ex lib/${NEW_OTP}_web.ex
git mv test/${CURRENT_OTP}_web test/${NEW_OTP}_web