Packages
phoenix_min
0.1.0
A post-installation tool that converts a default Phoenix installation to use LiveView-only with inline HEEx templates, removing controller-based infrastructure.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/phoenix_min.install.ex
defmodule Mix.Tasks.PhoenixMin.Install do
@moduledoc """
Installs Phoenix Min by converting a Phoenix app to LiveView-only with inline templates.
## Usage
$ mix phoenix_min.install
Or via Igniter:
$ mix igniter.install phoenix_min
## What it does
1. Updates router to use LiveView for the root route
2. Creates a HomeLive module with inline template
3. Converts layouts to inline templates
4. Converts error views to inline templates
5. Removes controller files and template directories
6. Updates tests to work with LiveView
## Options
This task currently has no options but will preserve your existing configuration:
- Works with or without Ecto
- Works with or without asset pipeline
- Works with or without Gettext
- Preserves your custom routes and configurations
"""
use Igniter.Mix.Task
@shortdoc "Converts Phoenix to LiveView-only with inline templates"
@impl Igniter.Mix.Task
def info(_argv, _composing_task) do
%Igniter.Mix.Task.Info{
group: :phoenix_min,
positional: [],
schema: [],
example: "mix phoenix_min.install"
}
end
@impl Igniter.Mix.Task
def igniter(igniter) do
app_name = Igniter.Project.Application.app_name(igniter)
web_module = PhoenixMin.web_module(app_name)
igniter
|> validate_phoenix_project()
|> PhoenixMin.Transforms.LiveViews.create_home_live(web_module)
|> PhoenixMin.Transforms.Router.update_to_liveview(web_module)
|> PhoenixMin.Transforms.Layouts.convert_to_inline(web_module)
|> PhoenixMin.Transforms.ErrorViews.convert_to_inline(web_module)
|> PhoenixMin.Transforms.Tests.update_test_files(web_module)
|> PhoenixMin.FileOperations.remove_controller_files(web_module)
|> add_success_message()
end
defp validate_phoenix_project(igniter) do
# Check if this is a Phoenix project by looking for the router
app_name = Igniter.Project.Application.app_name(igniter)
web_module = PhoenixMin.web_module(app_name)
router_module = Module.concat(web_module, Router)
{exists?, igniter} = Igniter.Project.Module.module_exists(igniter, router_module)
if exists? do
igniter
else
Igniter.add_warning(
igniter,
"""
Phoenix Min requires a Phoenix project but could not find #{inspect(router_module)}.
Please run this task from the root of a Phoenix project.
"""
)
end
end
defp add_success_message(igniter) do
Igniter.add_notice(
igniter,
"""
Phoenix Min installation complete! 🎉
Your Phoenix app has been converted to LiveView-only with inline templates.
Next steps:
1. Review the changes above
2. Run `mix test` to verify everything works
3. Start your server with `mix phx.server`
All your pages should now use LiveView with inline HEEx templates.
Check out `lib/your_app_web/home_live.ex` to see the pattern.
"""
)
end
end