loongmxbt
How to change a Phoenix Project name smoothly?
I use mix phoenix.new paper to create a new project paper.
So all the stuff is called Paper or :paper.
However, I have to define a model called paper. So I have something like defmodule Paper.Paper do.
When I have multiple aliaes, I need to move Paper.paper to the last.
I know I made a “stupid” codename that may interfere with the model name.
So how can I modify all the Paper. stuff and :paper stuff eaisly? Is there a Phoenix mix command to do that?
Thanks!
Marked As Solved
nerdyworm
I’ve been using this script for the two or three times I had to rename a phoenix project: rename a phoenix project · GitHub
requires ack to be installed, but you could certainly swap that out for grep.
Cheers,
Ben
Also Liked
jaysoifer
• Works on MacOS, not tested elsewhere.
• Needs: git, xargs and sed.
From the root folder of the project:
-
git grep -l 'old_name' | xargs sed -i '' -e 's/old_name/new_name/g' -
git grep -l 'OldName' | xargs sed -i '' -e 's/OldName/NewName/g' -
mv ./lib/old_name ./lib/new_name -
mv ./lib/old_name.ex ./lib/new_name.exIf you have a similar folder structure in the tests folder, you probably also need:
-
mv ./test/old_name ./test/new_name
benwilson512
There is not a command for renaming a project. I have however had to do so a couple times in the past, and in general global find and replace works really rather well. Just also move any directories named paper and you’re done.
Qqwy
A global find+replace works a lot better in Elixir than in most OOP-languages, because you always refer to a certain piece of code the same way: ModuleName.function_name. And structs use the ModuleName as well.
In OOP-languages, you can only hope that some object isn’t referred to under a different name.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









