-
Notifications
You must be signed in to change notification settings - Fork 176
/
json.ex
44 lines (37 loc) · 975 Bytes
/
json.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
44
defmodule ExCoveralls.Json do
@moduledoc """
Generate JSON output for results.
"""
@file_name "excoveralls.json"
@doc """
Provides an entry point for the module.
"""
def execute(stats, options \\ []) do
generate_json(stats, Enum.into(options, %{})) |> write_file(options[:output_dir])
ExCoveralls.Local.print_summary(stats)
end
def generate_json(stats, _options) do
Jason.encode!(%{
source_files: stats
})
end
defp output_dir(output_dir) do
cond do
output_dir ->
output_dir
true ->
options = ExCoveralls.Settings.get_coverage_options
case Map.fetch(options, "output_dir") do
{:ok, val} -> val
_ -> "cover/"
end
end
end
defp write_file(content, output_dir) do
file_path = output_dir(output_dir)
unless File.exists?(file_path) do
File.mkdir_p!(file_path)
end
File.write!(Path.expand(@file_name, file_path), content)
end
end