mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 23:27:54 +03:00
88e1d9dc28
* Sites API * Extract Revenue react api helpers * !fixup * Extract JS Money module to /extra * Extract Revenue full build extras (tests pass for full) * Update MIX_ENV=small mix test * Remove dead code * Add moduledocs * Add credo config * Trick dialyzer * DRY revenue metrics * Use more concise version of on_full_build macro * Disable credo check
53 lines
1.0 KiB
Elixir
53 lines
1.0 KiB
Elixir
defmodule Plausible do
|
|
@moduledoc """
|
|
Build-related macros
|
|
"""
|
|
|
|
@small_builds [:small, :small_test]
|
|
|
|
defmacro __using__(_) do
|
|
quote do
|
|
require Plausible
|
|
import Plausible
|
|
end
|
|
end
|
|
|
|
defmacro on_full_build(clauses) do
|
|
do_on_full_build(clauses)
|
|
end
|
|
|
|
def do_on_full_build(do: block) do
|
|
do_on_full_build(do: block, else: nil)
|
|
end
|
|
|
|
def do_on_full_build(do: do_block, else: else_block) do
|
|
if Mix.env() not in @small_builds do
|
|
quote do
|
|
unquote(do_block)
|
|
end
|
|
else
|
|
quote do
|
|
unquote(else_block)
|
|
end
|
|
end
|
|
end
|
|
|
|
defmacro full_build?() do
|
|
full_build? = Mix.env() not in @small_builds
|
|
|
|
# Tricking dialyzer as per:
|
|
# https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778
|
|
quote do
|
|
:erlang.phash2(1, 1) == 0 and unquote(full_build?)
|
|
end
|
|
end
|
|
|
|
defmacro small_build?() do
|
|
small_build? = Mix.env() in @small_builds
|
|
|
|
quote do
|
|
unquote(small_build?)
|
|
end
|
|
end
|
|
end
|