-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
compile.phoenix.ex
43 lines (37 loc) · 978 Bytes
/
compile.phoenix.ex
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
defmodule Mix.Tasks.Compile.Phoenix do
use Mix.Task
@recursive true
@moduledoc """
Compiles Phoenix source files that support code reloading.
"""
@doc false
def run(_args) do
{:ok, _} = Application.ensure_all_started(:phoenix)
case touch() do
[] -> :noop
_ -> :ok
end
end
@doc false
def touch do
Mix.Phoenix.modules
|> modules_for_recompilation
|> modules_to_file_paths
|> Stream.map(&touch_if_exists(&1))
|> Stream.filter(&(&1 == :ok))
|> Enum.to_list()
end
defp touch_if_exists(path) do
:file.change_time(path, :calendar.local_time())
end
defp modules_for_recompilation(modules) do
Stream.filter modules, fn mod ->
Code.ensure_loaded?(mod) and
function_exported?(mod, :__phoenix_recompile__?, 0) and
mod.__phoenix_recompile__?
end
end
defp modules_to_file_paths(modules) do
Stream.map(modules, fn mod -> mod.__info__(:compile)[:source] end)
end
end