From bb2b2fec7c1df6ada0e68442ded47efd85622500 Mon Sep 17 00:00:00 2001 From: Harlan T Wood Date: Sun, 8 Apr 2018 18:35:29 -1000 Subject: [PATCH 1/2] Default formatter config + run `mix format` --- .formatter.exs | 4 ++++ lib/remix.ex | 44 +++++++++++++++++++++++++++----------------- mix.exs | 17 +++++++++-------- 3 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 .formatter.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..525446d --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/lib/remix.ex b/lib/remix.ex index 3915d2d..8a35f4d 100644 --- a/lib/remix.ex +++ b/lib/remix.ex @@ -28,20 +28,25 @@ defmodule Remix do def handle_info(:poll_and_reload, state) do paths = Application.get_all_env(:remix)[:paths] - new_state = Map.new paths, fn (path) -> - current_mtime = get_current_mtime path - last_mtime = case Map.fetch(state, path) do - {:ok, val} -> val - :error -> nil - end - handle_path path, current_mtime, last_mtime - end + new_state = + Map.new(paths, fn path -> + current_mtime = get_current_mtime(path) + + last_mtime = + case Map.fetch(state, path) do + {:ok, val} -> val + :error -> nil + end + + handle_path(path, current_mtime, last_mtime) + end) Process.send_after(__MODULE__, :poll_and_reload, 1000) {:noreply, new_state} end def handle_path(path, current_mtime, current_mtime), do: {path, current_mtime} + def handle_path(path, current_mtime, _) do comp_elixir = fn -> Mix.Tasks.Compile.Elixir.run(["--ignore-module-conflict"]) end comp_escript = fn -> Mix.Tasks.Escript.Build.run([]) end @@ -49,39 +54,44 @@ defmodule Remix do case Application.get_all_env(:remix)[:silent] do true -> ExUnit.CaptureIO.capture_io(comp_elixir) + if Application.get_all_env(:remix)[:escript] == true do ExUnit.CaptureIO.capture_io(comp_escript) end _ -> comp_elixir.() + if Application.get_all_env(:remix)[:escript] == true do comp_escript.() end end + {path, current_mtime} end def get_current_mtime(dir) do case File.ls(dir) do {:ok, files} -> get_current_mtime(files, [], dir) - _ -> nil + _ -> nil end end def get_current_mtime([], mtimes, _cwd) do mtimes - |> Enum.sort - |> Enum.reverse - |> List.first + |> Enum.sort() + |> Enum.reverse() + |> List.first() end def get_current_mtime([h | tail], mtimes, cwd) do - mtime = case File.dir?("#{cwd}/#{h}") do - true -> get_current_mtime("#{cwd}/#{h}") - false -> File.stat!("#{cwd}/#{h}").mtime - end - get_current_mtime tail, [mtime | mtimes], cwd + mtime = + case File.dir?("#{cwd}/#{h}") do + true -> get_current_mtime("#{cwd}/#{h}") + false -> File.stat!("#{cwd}/#{h}").mtime + end + + get_current_mtime(tail, [mtime | mtimes], cwd) end end end diff --git a/mix.exs b/mix.exs index 5e13298..9eedb30 100644 --- a/mix.exs +++ b/mix.exs @@ -2,17 +2,18 @@ defmodule Remix.Mixfile do use Mix.Project def project do - [app: :remix, - version: "0.0.2", - elixir: "~> 1.0", - package: package, - description: description, - deps: deps] + [ + app: :remix, + version: "0.0.2", + elixir: "~> 1.0", + package: package, + description: description, + deps: deps + ] end def application do - [applications: [:logger], - mod: {Remix, []}] + [applications: [:logger], mod: {Remix, []}] end defp deps, do: [] From 8fdff45c3f990cd62357af5e324638b0c8c3004a Mon Sep 17 00:00:00 2001 From: Harlan T Wood Date: Sun, 8 Apr 2018 18:40:40 -1000 Subject: [PATCH 2/2] Silence warnings with function parens --- mix.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 9eedb30..452f108 100644 --- a/mix.exs +++ b/mix.exs @@ -6,9 +6,9 @@ defmodule Remix.Mixfile do app: :remix, version: "0.0.2", elixir: "~> 1.0", - package: package, - description: description, - deps: deps + package: package(), + description: description(), + deps: deps() ] end