forked from elixirscript/elixirscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.ex
More file actions
47 lines (38 loc) · 984 Bytes
/
Copy pathwatcher.ex
File metadata and controls
47 lines (38 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
defmodule ElixirScript.Watcher do
use GenServer
require Logger
@moduledoc """
Watches the input folder for changes and calls the ElixirScript compiler
"""
def start_link(input, options) do
GenServer.start_link(__MODULE__, [input: input, options: options])
end
def init(args) do
{:ok, _} = Application.ensure_all_started(:elixir_script)
{:ok, _} = Application.ensure_all_started(:fs)
:fs.subscribe()
{:ok, args}
end
def handle_info({_pid, {:fs, :file_event}, {path, event}}, state) do
try do
if input_changed?(to_string(path)) do
Logger.debug fn() ->
"Event: #{inspect event} Path: #{path}"
end
ElixirScript.Compiler.compile(state[:input], state[:options])
end
rescue
x ->
Logger.error(x.message)
end
{:noreply, state}
end
defp input_changed?(path) do
case Path.extname(path) do
".beam" ->
true
_ ->
false
end
end
end