diff options
Diffstat (limited to 'lib/mix/tasks/pleroma/instance.ex')
-rw-r--r-- | lib/mix/tasks/pleroma/instance.ex | 92 |
1 files changed, 89 insertions, 3 deletions
diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 91440b453..f57053a4c 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -33,7 +33,11 @@ defmodule Mix.Tasks.Pleroma.Instance do uploads_dir: :string, static_dir: :string, listen_ip: :string, - listen_port: :string + listen_port: :string, + fe_primary: :string, + fe_mastodon: :string, + fe_admin: :string, + fe_static: :string ], aliases: [ o: :output, @@ -158,7 +162,85 @@ defmodule Mix.Tasks.Pleroma.Instance do ) |> Path.expand() - Config.put([:instance, :static_dir], static_dir) + install_fe = + case Mix.env() do + :test -> + fn _, _ -> "42" end + + _ -> + fn frontend, callback -> + case Pleroma.Utils.command_available?("yarn") do + false when frontend != "none" -> + message = + "To install #{frontend} frontend, `yarn` command is required. Please install it before continue. ([C]ontinue/[A]bort)" + + case String.downcase(shell_prompt(message, "C")) do + abort when abort in ["a", "abort"] -> + "none" + + _continue -> + callback.(frontend, callback) + end + + _ -> + Mix.Tasks.Pleroma.Frontend.run([ + "install", + frontend, + "--static-dir", + static_dir + ]) + end + end + end + + fe_primary = + get_option( + options, + :fe_primary, + "Choose primary frontend for your instance (available: pleroma/kenoma/none)", + "pleroma" + ) + + fe_primary_ref = install_fe.(fe_primary, install_fe) + + enable_static_fe? = + get_option( + options, + :fe_static, + "Would you like to enable Static frontend (render profiles and posts using server-generated HTML that is viewable without using JavaScript)?", + "y" + ) === "y" + + install_mastodon_fe? = + get_option( + options, + :fe_mastodon, + "Would you like to install Mastodon frontend?", + "y" + ) === "y" + + fe_mastodon_ref = + case install_mastodon_fe? do + true -> + install_fe.("mastodon", install_fe) + + false -> + "none" + end + + install_admin_fe? = + get_option( + options, + :fe_admin, + "Would you like to install Admin frontend?", + "y" + ) === "y" + + fe_admin_ref = + case install_admin_fe? do + true -> install_fe.("admin", install_fe) + false -> "none" + end secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) jwt_secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) @@ -188,7 +270,11 @@ defmodule Mix.Tasks.Pleroma.Instance do uploads_dir: uploads_dir, rum_enabled: rum_enabled, listen_ip: listen_ip, - listen_port: listen_port + listen_port: listen_port, + fe_primary: %{"name" => fe_primary, "ref" => fe_primary_ref}, + fe_mastodon: %{"name" => "mastodon", "ref" => fe_mastodon_ref}, + fe_admin: %{"name" => "admin", "ref" => fe_admin_ref}, + enable_static_fe?: enable_static_fe? ) result_psql = |