defmodule LetMe.MixProject do
  use Mix.Project

  @source_url "https://github.com/woylie/let_me"
  @version "1.2.5"

  def project do
    [
      app: :let_me,
      version: @version,
      elixir: "~> 1.13",
      start_permanent: Mix.env() == :prod,
      elixirc_paths: elixirc_paths(Mix.env()),
      deps: deps(),
      test_coverage: [tool: ExCoveralls],
      preferred_cli_env: [
        coveralls: :test,
        "coveralls.detail": :test,
        "coveralls.post": :test,
        "coveralls.html": :test,
        "coveralls.github": :test
      ],
      dialyzer: [
        plt_file: {:no_warn, ".plts/dialyzer.plt"}
      ],
      name: "LetMe",
      source_url: @source_url,
      homepage_url: @source_url,
      description: description(),
      package: package(),
      docs: docs()
    ]
  end

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

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:castore, "== 1.0.14", only: :test},
      {:credo, "== 1.7.12", only: [:dev, :test], runtime: false},
      {:dialyxir, "== 1.4.5", only: [:dev, :test], runtime: false},
      {:ex_doc, "== 0.38.2", only: :dev, runtime: false},
      {:excoveralls, "== 0.18.5", only: :test}
    ]
  end

  defp description do
    "Authorization library with a DSL and introspection"
  end

  defp package do
    [
      licenses: ["MIT"],
      links: %{
        "GitHub" => @source_url,
        "Changelog" => @source_url <> "/blob/main/CHANGELOG.md",
        "Sponsor" => "https://github.com/sponsors/woylie"
      },
      files: ~w(lib .formatter.exs mix.exs README* LICENSE* CHANGELOG*)
    ]
  end

  defp docs do
    [
      main: "readme",
      extras: ["cheatsheets/rules.cheatmd", "README.md", "CHANGELOG.md"],
      source_ref: @version,
      skip_undefined_reference_warnings_on: ["CHANGELOG.md"],
      groups_for_extras: [
        Cheatsheets: ~r/cheatsheets\/.?/
      ]
    ]
  end
end
