Created
February 25, 2019 00:25
-
-
Save notactuallypagemcconnell/105ee138d3f634c9a7bc87f2942ee5eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# have this dep for dev AND test, not just test | |
# https://github.com/lpil/mix-test.watch/blob/master/lib/mix_test_watch/path.ex | |
defmodule Foobar.Recompiler do | |
use GenServer | |
def start_link(args) do | |
GenServer.start_link(__MODULE__, args) | |
end | |
def init(args) do | |
{:ok, watcher_pid} = FileSystem.start_link(dirs: ["./"], latency: 0) | |
FileSystem.subscribe(watcher_pid) | |
{:ok, %{watcher_pid: watcher_pid}} | |
end | |
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do | |
case String.ends_with?(path, ".ex") do | |
true -> Mix.Tasks.Compile.Elixir.run(["--ignore-module-conflict"]) | |
false -> :noop | |
end | |
{:noreply, state} | |
end | |
def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid}=state) do | |
# do we need logic for the monitor stop? we want it always running... | |
{:noreply, state} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment