How to rename an Elixir Phoenix app

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:


  1. Check in all your files into a git repo (git init ., git add -A, git commit -m 'initial commit')
  2. Create a new file and copy the code.
  3. Replace the variables NEW_NAME and NEW_OTP with the appropriate new names.
  4. Replace the variables CURRENT_NAME and CURRENT_OTP with the old names.
  5. Save the file, and execute the script in the terminal: sh
export LC_CTYPE=C
export LANG=C



set -e

if ! command -v ack &> /dev/null
    echo "\`ack\` could not be found. Please install it before continuing (Mac: brew install ack)."
    exit 1

ack -l $CURRENT_NAME | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g"
ack -l $CURRENT_OTP | 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


Rename Phoenix Project script from Petal Boilerplate

© 2023 Abhinav Saxena   •   Powered by Soopr   •   Theme  Moonwalk