2019-09-02 14:29:19 +03:00
|
|
|
defmodule Plausible do
|
|
|
|
@moduledoc """
|
2023-11-20 14:52:20 +03:00
|
|
|
Build-related macros
|
2019-09-02 14:29:19 +03:00
|
|
|
"""
|
2023-11-20 14:52:20 +03:00
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
@ce_builds [:ce, :ce_test, :ce_dev]
|
2023-11-20 14:52:20 +03:00
|
|
|
|
|
|
|
defmacro __using__(_) do
|
|
|
|
quote do
|
|
|
|
require Plausible
|
|
|
|
import Plausible
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
defmacro on_ee(clauses) do
|
|
|
|
do_on_ee(clauses)
|
2023-11-20 14:52:20 +03:00
|
|
|
end
|
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
defmacro on_ce(clauses) do
|
|
|
|
do_on_ce(clauses)
|
2023-11-22 17:34:47 +03:00
|
|
|
end
|
|
|
|
|
2024-05-29 15:55:25 +03:00
|
|
|
# :erlang.phash2(1, 1) == 0 tricks dialyzer as per:
|
|
|
|
# https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778
|
2023-11-20 14:52:20 +03:00
|
|
|
|
2024-05-29 15:55:25 +03:00
|
|
|
ee? = Mix.env() not in @ce_builds
|
|
|
|
def ee?, do: :erlang.phash2(1, 1) == 0 and unquote(ee?)
|
2023-11-20 14:52:20 +03:00
|
|
|
|
2024-05-29 15:55:25 +03:00
|
|
|
ce? = Mix.env() in @ce_builds
|
|
|
|
def ce?, do: :erlang.phash2(1, 1) == 0 and unquote(ce?)
|
2024-04-29 09:05:33 +03:00
|
|
|
|
|
|
|
defp do_on_ce(do: block) do
|
|
|
|
do_on_ee(do: nil, else: block)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp do_on_ee(do: block) do
|
|
|
|
do_on_ee(do: block, else: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp do_on_ee(do: do_block, else: else_block) do
|
|
|
|
if Mix.env() not in @ce_builds do
|
|
|
|
quote do
|
|
|
|
unquote(do_block)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
quote do
|
|
|
|
unquote(else_block)
|
|
|
|
end
|
2023-11-20 14:52:20 +03:00
|
|
|
end
|
|
|
|
end
|
2024-05-23 10:43:01 +03:00
|
|
|
|
|
|
|
if Mix.env() in @ce_builds do
|
|
|
|
def product_name do
|
|
|
|
"Plausible CE"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
def product_name do
|
|
|
|
"Plausible Analytics"
|
|
|
|
end
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|