sloane.sh/lib/mix/tasks/site.watch.ex

28 lines
584 B
Elixir
Raw Normal View History

2024-02-16 17:05:28 -05:00
defmodule Mix.Tasks.Site.Watch do
@moduledoc "Build and output the site as HTML watching for changes"
@shortdoc "build the site and watch for changes"
use Mix.Task
2024-02-16 17:27:46 -05:00
require Logger
2024-02-16 17:05:28 -05:00
@impl Mix.Task
def run(_args) do
2024-02-16 17:27:46 -05:00
Logger.info("Starting site.watch...")
2024-02-16 17:05:28 -05:00
{:ok, pid} = SloaneSH.watch()
unless iex_running?() do
ref = Process.monitor(pid)
receive do
{:DOWN, ^ref, _, _, _} ->
2024-02-16 17:27:46 -05:00
Logger.info("site.watch terminated")
2024-02-16 17:05:28 -05:00
:ok
end
end
end
defp iex_running? do
Code.ensure_loaded?(IEx) and IEx.started?()
end
end