A mountable library's installer, declared in one use:
defmodule Mix.Tasks.MyLib.Install do
use PhoenixMountable.Install,
otp_app: :my_lib,
mounts: [
{MyLib.Router, "/my_lib", scope: "/admin", options: "resolver: {web}.MyLibResolver"}
],
migrations: MyLib.Migrations,
hook: {"MyLib", "my_lib"},
css: ["my_lib.css", {"my_lib-dark.css", :comment}]
endHosts run mix igniter.install my_lib, which adds the dependency and
runs the task, or mix my_lib.install once the dependency is there.
Igniter shows every change as a diff
before it writes, and each step is idempotent, so running it again
changes nothing.
The steps, each one when its option is given, in this order:
:mounts- mounts each definition in the host's router (PhoenixMountable.Igniter.mount/4), with its options.:migrations- writes the migration that installs the library's tables, or upgrades them (PhoenixMountable.Igniter.gen_migration/3).:hook- adds a LiveView hook toassets/js/app.js(PhoenixMountable.Igniter.add_hook/4), for components that render in the host's own pages.:css- imports style sheets inassets/css/app.css(PhoenixMountable.Igniter.add_css_imports/4).:tailwind- makes the host's Tailwind scan the library (PhoenixMountable.Igniter.add_tailwind_source/2), for libraries styled by the host.:supervisor- starts the mounts' processes at boot (PhoenixMountable.Igniter.add_supervisor/2).
Then the library's own steps, in install/1 (a child of the host's
application with its options, a module of the host's to write):
@impl PhoenixMountable.Install
def install(igniter) do
Igniter.Project.Application.add_new_child(igniter, {MyLib, repo: MyApp.Repo})
endWithout Igniter
Igniter is an optional dependency of the library: in a host without it,
the task says how to get it, and how to make the changes by hand (the
:manual option, the text of the library's guide).
Options
:otp_app(atom/0) - Required. The library's application.:mounts(list ofterm/0) -{definition, path}or{definition, path, opts}, opts as inPhoenixMountable.Igniter.mount/4. The default value is[].:migrations(atom/0) - The library'sPhoenixMountable.Migrationsmodule.:hook(tuple ofString.t/0,String.t/0values) -{hook, package}: the hook's name and its npm package.:css(list ofterm/0) - Style sheets, as inPhoenixMountable.Igniter.add_css_imports/4. The default value is[].:tailwind(boolean/0) - Add the library to the host's Tailwind sources. The default value isfalse.:supervisor(boolean/0) - Start the mounts' processes at boot. The default value isfalse.:shortdoc(String.t/0) - The task's short doc. Defaults toInstalls <library> in a Phoenix app.:manual(String.t/0) - What to do by hand, for a host without Igniter.
Summary
Callbacks
The library's own steps, after the declared ones.