Packages

Run your tests against fake external services.

Current section

Files

Jump to
loopback mix.exs
Raw

mix.exs

defmodule Loopback.MixProject do
  use Mix.Project

  @version "0.1.0"
  @source_url "https://github.com/stefanchrobot/loopback"

  def project do
    [
      app: :loopback,
      version: @version,
      elixir: "~> 1.19",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      description: description(),
      package: package(),
      name: "Loopback",
      source_url: @source_url,
      docs: docs()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      mod: {Loopback.Application, []}
    ]
  end

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

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:nimble_ownership, "~> 1.0"},
      {:ex_doc, "~> 0.40", only: :dev, runtime: false},
      {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
      # Clients with interceptors with versions matching what's declared in the README.
      # hackney 2.x, 3.x, 4.0.0 and 4.0.1 lack functions that Tesla and HTTPoison use.
      {:finch, "~> 0.24", optional: true},
      {:hackney, "~> 1.21 or ~> 4.0 and >= 4.0.2", optional: true},
      {:tesla, "~> 1.22", optional: true},
      # Clients built on the ones above.
      {:httpoison, "~> 2.2 or ~> 3.0", only: :test},
      {:req, "~> 0.5", only: :test},
      # For Tesla.Adapter.Gun, which Tesla defines when gun is loaded.
      {:gun, "~> 2.0", only: :test}
    ]
  end

  defp description do
    "Run your tests against fake external services."
  end

  defp package do
    [
      licenses: ["MIT"],
      links: %{
        "GitHub" => @source_url,
        "Changelog" => "https://loopback.hexdocs.pm/changelog.html"
      }
    ]
  end

  defp docs do
    [
      main: "readme",
      extras: ["README.md", "CHANGELOG.md"],
      source_ref: "v#{@version}",
      before_closing_body_tag: &before_closing_body_tag/1,
      filter_modules: fn module, _metadata ->
        module not in [Loopback.Dispatcher, Loopback.ModuleOverride]
      end,
      skip_code_autolink_to: [
        "Loopback.Dispatcher",
        "Loopback.ModuleOverride",
        "Loopback.HTTPFake.request/2"
      ],
      groups_for_modules: [
        Interception: [
          Loopback.Interceptor,
          Loopback.Interceptors.Finch,
          Loopback.Interceptors.Hackney,
          Loopback.Interceptors.Httpc,
          Loopback.Interceptors.TeslaGun,
          Loopback.Interceptors.TeslaMint
        ],
        Fakes: [Loopback.HTTPFake, Loopback.HTTPFake.Router],
        HTTP: [Loopback.HTTPRequest, Loopback.HTTPResponse, Loopback.HTTPError]
      ]
    ]
  end

  # Renders ```mermaid code blocks, see https://ex-doc.hexdocs.pm/readme.html#rendering-mermaid-graphs
  defp before_closing_body_tag(:html) do
    """
    <script defer src="https://cdn.jsdelivr.net/npm/mermaid@11.17.2/dist/mermaid.min.js"></script>
    <script>
      let initialized = false;

      window.addEventListener("exdoc:loaded", async () => {
        if (!initialized) {
          mermaid.initialize({
            startOnLoad: false,
            look: "neo",
            theme: document.body.className.includes("dark") ? "neo-dark" : "neo",
            sequence: {diagramMarginX: 10}
          });
          initialized = true;
        }

        const codeEls = [...document.querySelectorAll("pre code.mermaid")];

        const svgEls = await Promise.all(
          codeEls.map(async (codeEl, id) => {
            const graphEl = document.createElement("div");
            const {svg, bindFunctions} = await mermaid.render("mermaid-graph-" + id, codeEl.textContent);
            graphEl.innerHTML = svg;
            bindFunctions?.(graphEl);
            codeEl.parentElement.replaceWith(graphEl);
            return graphEl.querySelector("svg");
          })
        );

        // Scales the diagrams on a page by the same factor, so that their text and shapes have
        // the same size. The widest one fits the page, none grows past its natural size, and
        // the narrower ones are centered.
        const widths = svgEls.map((svgEl) => svgEl.viewBox.baseVal.width);
        const maxWidth = Math.max(...widths);

        svgEls.forEach((svgEl, i) => {
          svgEl.style.width = (widths[i] / maxWidth) * 100 + "%";
          svgEl.style.maxWidth = widths[i] + "px";
          svgEl.style.display = "block";
          svgEl.style.margin = "0 auto";
        });
      });
    </script>
    """
  end

  defp before_closing_body_tag(:epub), do: ""
end