Packages

Alternera's Command step: calls any program that speaks the plugin hosts' protocol over MessagePack or JSON frames.

Current section

Files

Jump to

mix.exs

defmodule AlterneraPluginCommand.MixProject do
  use Mix.Project

  @version "0.9.0"
  @source_url "https://github.com/10e-ab/alternera-camel"

  def project do
    [
      app: :alternera_plugin_command,
      version: @version,
      description:
        "Alternera's Command step: calls any program that speaks the plugin hosts' protocol over MessagePack or JSON frames.",
      package: package(),
      docs: docs(),
      source_url: @source_url,
      elixir: "~> 1.19",
      # The LiveView compiler writes the editor's colocated hooks, if it ever
      # has any (`_build/<env>/phoenix-colocated/alternera_plugin_command/`),
      # which the proxy's `mix alternera.plugin_assets` imports into its bundle.
      compilers: [:phoenix_live_view] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # The command hosts' registries and pools start with the package, a
  # dependency of the proxy's application, so they are up before any
  # pipeline calls them.
  def application do
    [
      mod: {Alternera.Plugins.Command.Application, []},
      extra_applications: [:logger]
    ]
  end

  defp deps do
    [
      sdk(:alternera_plugin_sdk),
      sdk(:alternera_plugin_editor),
      # The plugin hosts' runtime and the step it runs.
      sibling(:alternera_plugin_hosts),
      {:ex_doc, "~> 0.34", only: :dev, runtime: false}
    ]
  end

  defp package do
    [
      licenses: ["Apache-2.0"],
      links: %{"GitHub" => @source_url, "Alternera" => "https://github.com/10e-ab/alternera"},
      files: ~w(lib docs mix.exs README.md LICENSE NOTICE)
    ]
  end

  defp docs do
    [
      main: "readme",
      extras: ["README.md"],
      source_ref: "v#{@version}",
      source_url_pattern:
        "#{@source_url}/blob/v#{@version}/alternera_plugin_command/%{path}#L%{line}"
    ]
  end

  # The plugin hosts' runtime, a sibling in this repository: by path while
  # they change together, by version when this package is published, as
  # a Hex package must be (`ALTERNERA_CAMEL_PUBLISH=1 mix hex.publish`).
  defp sibling(app) do
    case System.get_env("ALTERNERA_CAMEL_PUBLISH") do
      unset when unset in [nil, ""] -> {app, path: "../#{app}"}
      _publish -> {app, "~> " <> @version}
    end
  end

  # The SDK's packages from Hex (their source is github.com/10e-ab/alternera-sdk),
  # or from a checkout of that repository when ALTERNERA_SDK_PATH names one,
  # while a contract and this code change together. Overridden only from a
  # checkout, where the SDK's packages name each other by path: Hex refuses
  # to build a package with an overridden dependency.
  defp sdk(app) do
    case System.get_env("ALTERNERA_SDK_PATH") do
      unset when unset in [nil, ""] ->
        {app, "~> 0.9.0"}

      checkout ->
        # Absolute only: Mix evaluates a package's mix.exs from that package's
        # directory, where a relative path names somewhere else.
        if Path.type(checkout) != :absolute,
          do: Mix.raise("ALTERNERA_SDK_PATH must be an absolute path, got: #{checkout}")

        {app, path: Path.join(checkout, Atom.to_string(app)), override: true}
    end
  end
end