diff options
author | Roman Chvanikov <chvanikoff@pm.me> | 2020-07-27 16:02:31 +0300 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@pm.me> | 2020-07-27 16:02:31 +0300 |
commit | 06db5cb1a16722d4e699010c4a4fc71bb42725ec (patch) | |
tree | abe2b7d6d9f935935af873ef2367f79d3de91f52 | |
parent | 22c9d521ab37662288a77bc32af750f664b0077e (diff) |
Add mix task to install all frontends
-rw-r--r-- | lib/mix/tasks/pleroma/frontend.ex | 22 | ||||
-rw-r--r-- | test/tasks/frontend_test.exs | 30 |
2 files changed, 52 insertions, 0 deletions
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex index 14d47aaba..7ddd9360a 100644 --- a/lib/mix/tasks/pleroma/frontend.ex +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -30,6 +30,28 @@ defmodule Mix.Tasks.Pleroma.Frontend do "none" end + def run(["install", "all"]) do + {:ok, _} = Application.ensure_all_started(:pleroma) + + configs = Pleroma.Config.get(:frontends, %{}) + + with config <- configs[:primary], + frontend <- config["name"], + ref when ref != "none" <- config["ref"] do + run(["install", frontend, "--ref", ref]) + end + + with config <- configs[:mastodon], + ref when ref != "none" <- config["ref"] do + run(["install", "mastodon", "--ref", ref]) + end + + with config <- configs[:admin], + ref when ref != "none" <- config["ref"] do + run(["install", "admin", "--ref", ref]) + end + end + def run(["install", unknown_fe | _args]) when unknown_fe not in @known_frontends do shell_error( "Frontend \"#{unknown_fe}\" is not known. Known frontends are: #{ diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs index ba6bf7c40..273ac95e4 100644 --- a/test/tasks/frontend_test.exs +++ b/test/tasks/frontend_test.exs @@ -105,4 +105,34 @@ defmodule Mix.Tasks.Pleroma.FrontendTest do end end end + + describe "Install all" do + test "Normal config" do + config = [ + primary: %{"name" => "pleroma", "ref" => "1.2.3"}, + mastodon: %{"name" => "mastodon", "ref" => "2.3.4"}, + admin: %{"name" => "admin", "ref" => "3.4.5"} + ] + + Pleroma.Config.put(:frontends, config) + Mix.Tasks.Pleroma.Frontend.run(["install", "all"]) + + assert File.exists?(Path.join([@dir, "frontends/pleroma/1.2.3/index.html"])) + assert File.exists?(Path.join([@dir, "frontends/mastodon/2.3.4/sw.js"])) + assert File.exists?(Path.join([@dir, "frontends/admin/3.4.5/index.html"])) + end + + test "Unconfigured frontends" do + config = [ + primary: %{"name" => "none", "ref" => "1.2.3"}, + mastodon: %{"name" => "mastodon", "ref" => "none"}, + admin: %{"name" => "admin", "ref" => "none"} + ] + + Pleroma.Config.put(:frontends, config) + Mix.Tasks.Pleroma.Frontend.run(["install", "all"]) + + assert {:ok, []} == File.ls(@dir) + end + end end |