How to smoothly rename a Phoenix project?

I cloned a git repo and I need to start a new project based on it.

How to rename it, making sure everything is taken care of?

I am using macOS .

+5
source share
2 answers

Based on nerdyworm rename.sh , which uses ack , I adapted it to use git grep and ran macOS .

OTP NAME : Snake Case application name (snake_case) for the application.

NAME : name of the regular application.

 $ git grep -l $CURRENT_OTP | xargs sed -i '' -e "s/$CURRENT_OTP/$NEW_OTP/g" $ git grep -l $CURRENT_NAME | xargs sed -i '' -e "s/$CURRENT_NAME/$NEW_NAME/g" $ mv lib/$CURRENT_OTP lib/$NEW_OTP $ mv lib/$CURRENT_OTP.ex lib/$NEW_OTP.ex 
0
source

I do not know how to do this automatically with full accuracy, but these are the steps that I perform manually when I need to rename Phoenix projects.

The commands below assume that your code is in the git repository and the old application is my_app / MyApp and the new one is my_new_app / MyNewApp . The process is fragile - if your application or module name can be found in many places (for example, this is one letter A or something else), then this will not work.

 # search replace both the application name and module name in all files indexed by git $ git ls-files -z | xargs -0 perl -p -i -e 's/my_app/my_new_app/g; s/MyApp/MyNewApp/g;' # rename `lib/my_app` $ mv lib/my_app lib/my_new_app 

After that, I run mix test and fix any compilation errors or testing errors.

Finally, I will quickly look through git diff to make sure everything looks right.

0
source

Source: https://habr.com/ru/post/1266494/


All Articles