Skip to content

Commit f79b14c

Browse files
laurinenasjosevalim
authored andcommitted
Run code formatter on Mix.Tasks.Archive.Build (#6885)
1 parent 1d602f6 commit f79b14c

File tree

1 file changed

+55
-40
lines changed

1 file changed

+55
-40
lines changed

lib/mix/lib/mix/tasks/archive.build.ex

+55-40
Original file line numberDiff line numberDiff line change
@@ -42,79 +42,94 @@ defmodule Mix.Tasks.Archive.Build do
4242
* `--include-dot-files` - adds dot files from priv directory to the archive.
4343
4444
"""
45-
@switches [force: :boolean, compile: :boolean, output: :string, input: :string,
46-
deps_check: :boolean, archives_check: :boolean, elixir_version_check: :boolean,
47-
include_dot_files: :boolean]
45+
@switches [
46+
force: :boolean,
47+
compile: :boolean,
48+
output: :string,
49+
input: :string,
50+
deps_check: :boolean,
51+
archives_check: :boolean,
52+
elixir_version_check: :boolean,
53+
include_dot_files: :boolean
54+
]
4855

4956
def run(args) do
5057
{opts, _} = OptionParser.parse!(args, aliases: [o: :output, i: :input], strict: @switches)
5158

52-
project = Mix.Project.get
59+
project = Mix.Project.get()
5360

5461
if project && Keyword.get(opts, :compile, true) do
55-
Mix.Task.run :compile, args
62+
Mix.Task.run(:compile, args)
5663
end
5764

58-
source = cond do
59-
input = opts[:input] ->
60-
input
61-
project ->
62-
path = Mix.Project.app_path
63-
if elixir = Mix.Project.config[:elixir] do
64-
File.write Path.join(path, ".elixir"), elixir
65-
else
66-
File.rm Path.join(path, ".elixir")
67-
end
68-
path
69-
true ->
70-
Mix.raise "Cannot create archive without input directory, " <>
71-
"please pass -i as an option"
72-
end
65+
source =
66+
cond do
67+
input = opts[:input] ->
68+
input
7369

74-
project_config = Mix.Project.config
75-
target = cond do
76-
output = opts[:output] ->
77-
output
78-
project_config[:app] ->
79-
Mix.Local.name_for(:archive, project_config)
80-
true ->
81-
Mix.raise "Cannot create archive without output file, " <>
82-
"please pass -o as an option"
83-
end
70+
project ->
71+
path = Mix.Project.app_path()
72+
73+
if elixir = Mix.Project.config()[:elixir] do
74+
File.write(Path.join(path, ".elixir"), elixir)
75+
else
76+
File.rm(Path.join(path, ".elixir"))
77+
end
78+
79+
path
80+
81+
true ->
82+
Mix.raise("Cannot create archive without input directory, please pass -i as an option")
83+
end
84+
85+
project_config = Mix.Project.config()
86+
87+
target =
88+
cond do
89+
output = opts[:output] ->
90+
output
91+
92+
project_config[:app] ->
93+
Mix.Local.name_for(:archive, project_config)
94+
95+
true ->
96+
Mix.raise("Cannot create archive without output file, please pass -o as an option")
97+
end
8498

8599
unless File.dir?(source) do
86-
Mix.raise "Expected archive source #{inspect source} to be a directory"
100+
Mix.raise("Expected archive source #{inspect(source)} to be a directory")
87101
end
88102

89103
create(source, target, Keyword.get(opts, :include_dot_files, false))
90104

91-
Mix.shell.info "Generated archive #{inspect target} with MIX_ENV=#{Mix.env}"
105+
Mix.shell().info("Generated archive #{inspect(target)} with MIX_ENV=#{Mix.env()}")
92106
:ok
93107
end
94108

95109
defp create(source, target, include_dot_files?) do
96110
source_path = Path.expand(source)
97111
target_path = Path.expand(target)
98-
dir = Mix.Local.archive_name(target_path) |> String.to_charlist
99-
{:ok, _} = :zip.create(String.to_charlist(target_path),
100-
files_to_add(source_path, dir, include_dot_files?))
112+
dir = Mix.Local.archive_name(target_path) |> String.to_charlist()
113+
file_list = files_to_add(source_path, dir, include_dot_files?)
114+
{:ok, _} = :zip.create(String.to_charlist(target_path), file_list)
101115
:ok
102116
end
103117

104118
defp files_to_add(path, dir, include_dot_files?) do
105-
File.cd! path, fn ->
119+
File.cd!(path, fn ->
106120
evsn = Path.wildcard(".elixir")
107121
ebin = Path.wildcard("ebin/*.{beam,app}")
108122
priv = Path.wildcard("priv/**/*", match_dot: include_dot_files?)
109123

110-
Enum.reduce evsn ++ ebin ++ priv, [], fn(f, acc) ->
124+
Enum.reduce(evsn ++ ebin ++ priv, [], fn f, acc ->
111125
case File.read(f) do
112126
{:ok, bin} ->
113-
[{Path.join(dir, f) |> String.to_charlist, bin} | acc]
127+
[{Path.join(dir, f) |> String.to_charlist(), bin} | acc]
128+
114129
{:error, _} ->
115130
acc
116131
end
117-
end
118-
end
132+
end)
133+
end)
119134
end
120135
end

0 commit comments

Comments
 (0)