ex_watcher
An Elixir file change watcher based on fs
System Support
Just like fs
- Mac fsevent
- Linux inotify
- Windows inotify-win (untested)
NOTE: On Linux you need to install inotify-tools ./scripts/install_inotify.sh.
Usage
Put ex_watcher in the deps and application part of your mix.exs
defmodule MyProject.Mixfile do
use Mix.Project
# ...
def application do
[applications: [:exfswatch, :logger]]
end
defp deps do
[
{:exfswatch, "~> 0.1.0"},
]
end
# ...
end
write lib/monitor.ex
defmodule Monitor do
use ExWatcher.Watcher, dirs: ["/tmp/fswatch"]
def callback(:stop) do
IO.puts("STOP")
end
def callback(file_path, events) do
IO.inspect({file_path, events})
end
endExecute in iex
iex > Monitor.start()List Events from Backend
iex > ExWatcher.known_events()Installation
If available in Hex, the package can be installed as:
-
Add
ex_watcherto your list of dependencies inmix.exs:
```elixir
def deps do
[{:ex_watcher, "~> 0.1.0"}]
end
```-
Ensure
ex_watcheris started before your application:
```elixir
def application do
[applications: [:ex_watcher]]
end
```