forked from philss/floki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmix.exs
109 lines (96 loc) · 2.98 KB
/
mix.exs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
defmodule Floki.Mixfile do
use Mix.Project
@description "Floki is a simple HTML parser that enables search for nodes using CSS selectors."
@version "0.29.0"
def project do
[
app: :floki,
name: "Floki",
version: @version,
description: @description,
elixir: "~> 1.8",
package: package(),
erlc_paths: ["src", "gen"],
deps: deps(),
aliases: aliases(),
dialyzer: [
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
],
source_url: "https://github.com/philss/floki",
docs: [extras: ["README.md"], main: "Floki", assets: "assets"]
]
end
def application do
[extra_applications: [:logger]]
end
defp deps do
# Needed to avoid installing unnecessary deps on the CI
parsers_deps = [
html5ever: {:html5ever, ">= 0.8.0", optional: true, only: [:dev, :test]},
fast_html: {:fast_html, ">= 0.0.0", optional: true, only: [:dev, :test]}
]
parsers =
case System.get_env("PARSER") do
nil -> [:fast_html, :html5ever]
parser when parser in ~w(html5ever fast_html) -> [String.to_atom(parser)]
_ -> []
end
|> Enum.map(fn name -> Keyword.fetch!(parsers_deps, name) end)
[
{:html_entities, "~> 0.5.0"},
{:earmark, "~> 1.2", only: :dev},
{:ex_doc, "~> 0.23.0", only: :dev},
{:benchee, "~> 1.0.1", only: :dev},
{:credo, ">= 0.0.0", only: [:dev, :test]},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false},
{:inch_ex, "~> 2.1.0-rc.1", only: :docs}
] ++ parsers
end
defp aliases do
# Hardcoded because we can't load the floki application and get the module list at this point.
parsers = [Floki.HTMLParser.Mochiweb, Floki.HTMLParser.FastHtml, Floki.HTMLParser.Html5ever]
{aliases, cli_names} =
Enum.map_reduce(parsers, [], fn parser, acc ->
cli_name =
parser
|> Module.split()
|> List.last()
|> Macro.underscore()
{{:"test.#{cli_name}", &test_with_parser(parser, &1)}, [cli_name | acc]}
end)
aliases
|> Keyword.put(:test, &test_with_parser(cli_names, &1))
end
defp test_with_parser(parser_cli_names, args) when is_list(parser_cli_names) do
Enum.each(parser_cli_names, fn cli_name ->
Mix.shell().cmd("mix test.#{cli_name} --color #{Enum.join(args, " ")}",
env: [{"MIX_ENV", "test"}]
)
end)
end
defp test_with_parser(parser, args) do
Mix.shell().info("Running tests with #{parser}")
Application.put_env(:floki, :html_parser, parser, persistent: true)
Mix.env(:test)
Mix.Tasks.Test.run(args)
end
defp package do
%{
maintainers: ["Philip Sampaio Silva"],
licenses: ["MIT"],
files: [
"lib",
"src/*.xrl",
"src/floki_mochi_html.erl",
"mix.exs",
"README.md",
"LICENSE",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.md"
],
links: %{
"GitHub" => "https://github.com/philss/floki"
}
}
end
end