Current section

Files

Jump to

mix.exs

defmodule PhoenixKitComments.MixProject do
  use Mix.Project

  @version "0.4.8"
  @source_url "https://github.com/BeamLabEU/phoenix_kit_comments"

  def project do
    [
      app: :phoenix_kit_comments,
      version: @version,
      elixir: "~> 1.18",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      aliases: aliases(),

      # Hex
      description:
        "Comments module for PhoenixKit — polymorphic threading, likes/dislikes, and moderation",
      package: package(),

      # Dialyzer
      dialyzer: [
        plt_add_apps: [:phoenix_kit],
        ignore_warnings: ".dialyzer_ignore.exs",
        list_unused_filters: true
      ],

      # Docs
      name: "PhoenixKitComments",
      source_url: @source_url,
      docs: docs()
    ]
  end

  def application do
    [
      extra_applications: [:logger, :phoenix_kit]
    ]
  end

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  defp aliases do
    [
      quality: ["format", "credo --strict", "dialyzer"],
      "quality.ci": ["format --check-formatted", "credo --strict", "dialyzer"],
      precommit: [
        "compile --force --warnings-as-errors",
        "deps.unlock --check-unused",
        # Scan for retired Hex deps. Run via `cmd` so Hex bootstraps in a fresh
        # process — the hex.* archive tasks aren't resolvable via Mix.Task.run
        # inside an alias.
        "cmd mix hex.audit",
        "quality.ci"
      ]
    ]
  end

  # phoenix_kit resolves from Hex by default. For cross-repo work against a
  # local checkout, export PHOENIX_KIT_PATH=../phoenix_kit. Unset => the
  # published pin, so mix hex.publish / CI are unaffected.
  defp pk_dep(app, requirement, opts \\ []) do
    env_var = String.upcase(Atom.to_string(app)) <> "_PATH"

    case System.get_env(env_var) do
      nil when opts == [] -> {app, requirement}
      nil -> {app, requirement, opts}
      path -> {app, [path: path, override: true] ++ opts}
    end
  end

  defp deps do
    [
      # PhoenixKit provides the Module behaviour and Settings API.
      # ⚠️ Comment attribution (`author_display_name`, `attribution_mode`,
      # `attributed_project_uuid`, `attributed_label` on
      # `phoenix_kit_comments`) needs core migration V166, which this floor
      # still predates — a host at the floor gets a missing-column error
      # from `get_comment_tree/2`. Deliberately not raised further because
      # the core release carrying V166 is unpublished; bump it as part of
      # releasing that. `display_name/1` is already guarded at the call site
      # for the same reason.
      pk_dep(:phoenix_kit, "~> 2.0"),

      # LiveView is needed for the admin pages.
      {:phoenix_live_view, "~> 1.1"},

      # Phoenix.LiveViewTest parses rendered HTML with this from LV 1.1 on;
      # without it `element/2` and `has_element?/2` raise.
      {:lazy_html, "~> 0.1", only: :test},

      # Giphy API client used by the optional Giphy picker in the comment form.
      {:giphy_api, "~> 0.1.1"},

      # NOTE: markdown rendering uses MDEx (lib/.../web/markdown.ex calls it
      # directly), but mdex is NOT declared here — phoenix_kit core depends on
      # it and provides it transitively, so every module shares one resolved
      # version. Same arrangement as leaf. Don't re-add a direct mdex dep.

      # Optional: add ex_doc for generating documentation
      {:ex_doc, "~> 0.34", only: :dev, runtime: false},

      # Code quality
      {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
      {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
    ]
  end

  defp package do
    [
      licenses: ["MIT"],
      links: %{"GitHub" => @source_url},
      files: ~w(lib priv .formatter.exs mix.exs README.md CHANGELOG.md LICENSE)
    ]
  end

  defp docs do
    [
      main: "PhoenixKitComments",
      source_ref: "v#{@version}"
    ]
  end
end