PhoenixMountable.Install behaviour (PhoenixMountable v0.2.1)

Copy Markdown View Source

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}]
end

Hosts 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:

  1. :mounts - mounts each definition in the host's router (PhoenixMountable.Igniter.mount/4), with its options.
  2. :migrations - writes the migration that installs the library's tables, or upgrades them (PhoenixMountable.Igniter.gen_migration/3).
  3. :hook - adds a LiveView hook to assets/js/app.js (PhoenixMountable.Igniter.add_hook/4), for components that render in the host's own pages.
  4. :css - imports style sheets in assets/css/app.css (PhoenixMountable.Igniter.add_css_imports/4).
  5. :tailwind - makes the host's Tailwind scan the library (PhoenixMountable.Igniter.add_tailwind_source/2), for libraries styled by the host.
  6. :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})
end

Without 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

Summary

Callbacks

The library's own steps, after the declared ones.

Callbacks

install(igniter)

(optional)
@callback install(igniter :: term()) :: term()

The library's own steps, after the declared ones.