Skip to content

Commit

Permalink
fixes #1 issue (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eiji7 authored and minhajuddin committed Dec 12, 2017
1 parent c91b7a5 commit 8be397c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/mix_script.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@ defmodule MixScript do
mix_exs_path
|> File.stream!
|> Enum.to_list
|> Enum.reduce({"", []}, fn line, {prev_line, acc} ->
line_to_be_appended =
|> Enum.reduce({"", [], false}, fn line, {prev_line, acc, prev_removed} ->
prev_starts_deps = String.contains?(prev_line, "defp deps do")
curr_ends_func = line == " end\n"
remove_curr = (prev_starts_deps or prev_removed) and not curr_ends_func
result =
cond do
String.contains?(prev_line, "defp deps do") -> mix_deps
Regex.match?(~r[^\s*elixir: ".*",\s*$],prev_line) -> "escript: [main_module: MixScript],\n"
true -> line
prev_starts_deps and curr_ends_func -> [mix_deps | [line | acc]]
prev_starts_deps -> [mix_deps | acc]
remove_curr -> acc
Regex.match?(~r[^\s*elixir: ".*",\s*$], prev_line) ->
escript_line = "escript: [main_module: MixScript],\n"
[escript_line | [line | acc]]
true -> [line | acc]
end

{line, [line_to_be_appended | acc]}
{line, result, remove_curr}
end)
|> elem(1)
|> Enum.reverse
Expand Down

0 comments on commit 8be397c

Please sign in to comment.