1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Pleroma do
6 @apps [:restarter, :ecto, :ecto_sql, :postgrex, :db_connection, :cachex]
7 @cachex_childs ["object", "user"]
8 @doc "Common functions to be reused in mix tasks"
10 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
12 if Pleroma.Config.get(:env) != :test do
13 Application.put_env(:logger, :console, level: :debug)
17 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
23 Enum.each(apps, &Application.ensure_all_started/1)
25 childs = [Pleroma.Repo, Pleroma.Config.TransferTask, Pleroma.Web.Endpoint]
27 cachex_childs = Enum.map(@cachex_childs, &Pleroma.Application.build_cachex(&1, []))
29 Supervisor.start_link(childs ++ cachex_childs,
30 strategy: :one_for_one,
31 name: Pleroma.Supervisor
34 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
39 defp pleroma_rebooted? do
40 if Restarter.Pleroma.rebooted?() do
49 Application.load(:pleroma)
52 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
53 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
56 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
57 prompt_message = "#{prompt} [#{defname || defval}] "
61 do: Mix.shell().prompt(prompt_message),
62 else: :io.get_line(prompt_message)
68 shell_prompt(prompt, defval, defname)
79 def shell_yes?(message) do
81 do: Mix.shell().yes?("Continue?"),
82 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
85 def shell_info(message) do
87 do: Mix.shell().info(message),
88 else: IO.puts(message)
91 def shell_error(message) do
93 do: Mix.shell().error(message),
94 else: IO.puts(:stderr, message)
97 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
98 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
100 def escape_sh_path(path) do
101 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')