Phoenix - allow specifying project template path in phx.new

mix phx.new generates a project by scaffolding templates specified at installer/templates and I think it could be a good idea to allow passing an argument to mix phx.new which will override path where to look for templates first. Let’s say I run mix phx.new myapp --templates-path=~/phx_tpl/blog and I have the following structure in ~/phx_tpl/blog:

blog
├── phx_single
│   ├── config
│   │   └── dev.exs
│   ├── lib
│   │   └── app_name
│   │       └── web
│   │           └── web.ex
│   └── mix.exs
├── phx_test
│   └── controllers
│       └── page_controller_test.exs
└── phx_web
    └── controllers
        └── page_controller.ex

In this case project generated would have following files being generated from custom templates:

myapp
├── config
│   ├── dev.exs
├── lib
│   └── app
│       └── web
│           └── controllers
│               └── page_controller.ex
├── mix.exs
└── test
    └── web
        └── controllers
            └── page_controller_test.exs

while the rest of the app will be generated from Phoenix default templates.
I’m very interested in what community and, particularly, Phoenix maintainers, would think about it.

1 Like

You can put custom templates in priv/templates ( https://stackoverflow.com/questions/33404321/how-do-i-create-and-integrate-a-set-of-custom-templates-into-the-phoenix-framewo )

You could also look at https://pragdave.me/blog/2017/04/18/elixir-project-generator.html if you want more customization.

1 Like

Seems not quite what I’ve meant:
priv/templates can be used for overriding templates from phoenix_root/priv/templates, while I was asking about phoenix_root/installer/templates and while first is useable because you have mix task (ex.) phx.gen.html in deps/phoenix, the phx.new one comes from phx_new archive.
The second option is a bit different as well and is about writing app template from scratch, not allowing to extend phx.new how I want.
Actually, I ended up just rewriting Phoenix installer (https://github.com/reph-stack/reph), that works, but that feels like a big hack and that’s why I’m asking about support for Phx installer templates as an option.