# `PhoenixMountable.Install`
[🔗](https://github.com/hattoriai/phoenix_mountable/blob/v0.2.1/lib/phoenix_mountable/install.ex#L1)

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](https://hexdocs.pm/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 `c: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

* `:otp_app` (`t:atom/0`) - Required. The library's application.

* `:mounts` (list of `t:term/0`) - `{definition, path}` or `{definition, path, opts}`, opts as in `PhoenixMountable.Igniter.mount/4`. The default value is `[]`.

* `:migrations` (`t:atom/0`) - The library's `PhoenixMountable.Migrations` module.

* `:hook` (tuple of `t:String.t/0`, `t:String.t/0` values) - `{hook, package}`: the hook's name and its npm package.

* `:css` (list of `t:term/0`) - Style sheets, as in `PhoenixMountable.Igniter.add_css_imports/4`. The default value is `[]`.

* `:tailwind` (`t:boolean/0`) - Add the library to the host's Tailwind sources. The default value is `false`.

* `:supervisor` (`t:boolean/0`) - Start the mounts' processes at boot. The default value is `false`.

* `:shortdoc` (`t:String.t/0`) - The task's short doc. Defaults to `Installs <library> in a Phoenix app`.

* `:manual` (`t:String.t/0`) - What to do by hand, for a host without Igniter.

# `install`
*optional* 

```elixir
@callback install(igniter :: term()) :: term()
```

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
