igniter/lib/mix/task.ex

37 lines
1.1 KiB
Elixir
Raw Normal View History

2024-05-28 15:30:41 +12:00
defmodule Igniter.Mix.Task do
@moduledoc "A behaviour for implementing a Mix task that is enriched to be composable with other Igniter tasks."
2024-06-13 11:37:32 +12:00
@doc """
Whether or not it supports being run in the root of an umbrella project
At the moment, this is still experimental and we suggest not turning it on.
"""
2024-05-28 15:30:41 +12:00
@callback supports_umbrella?() :: boolean()
2024-06-13 11:37:32 +12:00
@doc "All the generator behavior happens here, you take an igniter and task arguments, and return an igniter."
2024-05-28 15:30:41 +12:00
@callback igniter(igniter :: Igniter.t(), argv :: list(String.t())) :: Igniter.t()
defmacro __using__(_opts) do
quote do
use Mix.Task
@behaviour Igniter.Mix.Task
def run(argv) do
if !supports_umbrella?() && Mix.Project.umbrella?() do
raise """
Cannot run #{inspect(__MODULE__)} in an umbrella project.
"""
end
Application.ensure_all_started([:rewrite])
Igniter.new()
|> igniter(argv)
|> Igniter.do_or_dry_run(argv)
2024-05-28 15:30:41 +12:00
end
def supports_umbrella?, do: false
defoverridable supports_umbrella?: 0
end
end
end