Building blocks for a mountable library's Igniter installer.
With them, a library's mix my_lib.install is a few lines:
defmodule Mix.Tasks.MyLib.Install do
use Igniter.Mix.Task
@impl Igniter.Mix.Task
def info(_argv, _parent), do: %Igniter.Mix.Task.Info{group: :my_lib}
@impl Igniter.Mix.Task
def igniter(igniter) do
igniter
|> PhoenixMountable.Igniter.mount(MyLib.Router, "/my_lib")
|> PhoenixMountable.Igniter.gen_migration(MyLib.Migrations)
|> PhoenixMountable.Igniter.add_tailwind_source(:my_lib)
end
endHosts then run mix igniter.install my_lib. Every step is idempotent, so
running the installer again changes nothing.
For upgrades, call gen_migration/3 from the library's Igniter upgrader:
it writes the migration from the host's pinned version to the latest, or
nothing when the host is up to date.
Summary
Functions
Starts the processes of every mount at boot: adds
{PhoenixMountable.Supervisor, router: ..., endpoint: ...} to the host's
application, after its endpoint.
Makes the host's Tailwind scan the library's templates, for libraries
styled by the host (PhoenixMountable.Assets.Host).
Writes the migration that installs the library, or upgrades it from the version the host's migrations pin, to the latest version.
Mounts the library in the host's router, inside the scope piped through
:browser.
Functions
Starts the processes of every mount at boot: adds
{PhoenixMountable.Supervisor, router: ..., endpoint: ...} to the host's
application, after its endpoint.
Makes the host's Tailwind scan the library's templates, for libraries
styled by the host (PhoenixMountable.Assets.Host).
Tailwind v4 (Phoenix 1.8): adds @source "../../deps/<app>"; to
assets/css/app.css. Tailwind v3 (Phoenix 1.7): adds
"../deps/<app>/**/*.*ex" to the content of assets/tailwind.config.js.
Writes the migration that installs the library, or upgrades it from the version the host's migrations pin, to the latest version.
Options
:repo— the repo (asked, or the only one):to— the version. Defaults to the latest.
Mounts the library in the host's router, inside the scope piped through
:browser.
Options
:router— the router (asked, or the only one):options— mount options, as a string of Elixir code ("resolver: MyApp.MyLibResolver"):pipelines— the pipelines of the scope. Defaults to[:browser].