Skip to main content

mix.exs

defmodule Shadix.MixProject do
  use Mix.Project

  @version "0.0.1"
  @source_url "https://tangled.org/workinghypothes.is/shadix"

  def project do
    [
      app: :shadix,
      version: @version,
      elixir: "~> 1.20",
      start_permanent: Mix.env() in [:prod, :docs],
      elixirc_paths: elixirc_paths(Mix.env()),
      deps: deps(),
      aliases: aliases(),
      description: "shadcn-style copy-paste UI components for Phoenix LiveView",
      package: package(),
      source_url: @source_url,
      docs: docs(),
      releases: releases()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  #
  # The docs deployment (built with MIX_ENV=docs) starts a supervised endpoint
  # via Shadix.Website.Application. When Shadix is consumed as a library dependency it is
  # compiled in :prod, so `mod:` is absent and no server is ever started.
  def application do
    [extra_applications: [:logger]] ++ docs_application(Mix.env())
  end

  defp docs_application(:docs), do: [mod: {Shadix.Website.Application, []}]
  defp docs_application(_), do: []

  # The deployable docs site (the dev harness compiled for production). Built
  # with `MIX_ENV=docs mix release shadix_docs`; see Dockerfile / fly.toml.
  defp releases do
    [
      shadix_docs: [
        include_executables_for: [:unix],
        applications: [shadix: :permanent]
      ]
    ]
  end

  # The docs site lives in website/ and is only compiled outside :prod.
  # The :docs env compiles it for the production docs-site release.
  defp elixirc_paths(:prod), do: ["lib"]
  defp elixirc_paths(:test), do: ["lib", "website", "test/support"]
  defp elixirc_paths(:docs), do: ["lib", "website"]
  defp elixirc_paths(_), do: ["lib", "website"]

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:phoenix_live_view, "~> 1.1"},
      {:jason, "~> 1.4"},

      # Dev/test harness + docs deployment: assertion helpers and TS hook builds.
      # The :docs env reuses these to build the public site.
      # (phoenix itself arrives transitively via phoenix_live_view)
      {:esbuild, "~> 0.10", only: [:dev, :docs], runtime: false},
      {:floki, "~> 0.38", only: :test},
      {:lazy_html, ">= 0.1.0", only: :test},
      {:ex_doc, ">= 0.0.0", only: :dev, runtime: false},

      # HEEx syntax highlighting for the component docs (server-side, no JS dep).
      {:makeup_eex, "~> 2.0", only: [:dev, :test, :docs]},
      {:makeup_html, ">= 0.0.0", only: [:dev, :test, :docs]},

      # Icons for the docs-site examples (not used by the library itself).
      {:phosphor_live_view, "~> 2.1", only: [:dev, :test, :docs]},

      # Dev harness / docs-site HTTP server + Tailwind v4 CLI wrapper.
      {:bandit, "~> 1.5", only: [:dev, :docs]},
      {:tailwind, "~> 0.3", only: [:dev, :docs], runtime: false}
    ]
  end

  defp aliases do
    [
      "assets.build": ["tailwind app", "esbuild docs"],
      dev: ["run --no-halt dev.exs"]
    ]
  end

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

  defp docs do
    [
      main: "readme",
      extras: ["README.md"],
      source_ref: "v#{@version}"
    ]
  end
end