defmodule Forum.Assets do
  @moduledoc false

  def path(relative_path) do
    source_path = Path.expand(Path.join("priv", relative_path), File.cwd!())

    if File.exists?(source_path) do
      source_path
    else
      Application.app_dir(:forum, Path.join("priv", relative_path))
    end
  end

  def paths(relative_glob) do
    source_pattern = Path.expand(Path.join("priv", relative_glob), File.cwd!())
    release_pattern = Application.app_dir(:forum, Path.join("priv", relative_glob))

    case Path.wildcard(source_pattern) do
      [] -> Path.wildcard(release_pattern)
      paths -> paths
    end
  end
end
