aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/administration/CLI_tasks/frontend.md18
-rw-r--r--lib/mix/tasks/pleroma/frontend.ex54
2 files changed, 72 insertions, 0 deletions
diff --git a/docs/administration/CLI_tasks/frontend.md b/docs/administration/CLI_tasks/frontend.md
new file mode 100644
index 000000000..d2c183d5b
--- /dev/null
+++ b/docs/administration/CLI_tasks/frontend.md
@@ -0,0 +1,18 @@
+# Managing frontends
+
+{! backend/administration/CLI_tasks/general_cli_task_info.include !}
+
+## Download the latest frontend
+
+This downloads a snapshot of the latest Pleroma-FE for a given reference and writes it to the `static_dir`. In a default setup, this means that this snapshot will be served as the frontend by the backend.
+
+```sh tab="OTP"
+ ./bin/pleroma_ctl pleroma.frontend download [<options>]
+```
+
+```sh tab="From Source"
+mix pleroma.frontend download [<options>]
+```
+
+### Options
+- `--reference <reference>` - Specify the reference that will be downloaded. Defaults to `master`.
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex
new file mode 100644
index 000000000..7a691b95d
--- /dev/null
+++ b/lib/mix/tasks/pleroma/frontend.ex
@@ -0,0 +1,54 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.Frontend do
+ use Mix.Task
+ alias __MODULE__.Fetcher
+
+ @shortdoc "Manages the Pleroma frontends"
+ @moduledoc File.read!("docs/administration/CLI_tasks/frontend.md")
+
+ def run(["download" | rest]) do
+ {options, [], []} =
+ OptionParser.parse(
+ rest,
+ strict: [
+ reference: :string
+ ]
+ )
+
+ reference = options[:reference] || "master"
+
+ IO.puts("Downloading reference #{reference}")
+
+ url =
+ "https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/#{reference}/download?job=build"
+
+ sd = Pleroma.Config.get([:instance, :static_dir]) |> Path.expand()
+
+ with {_, {:ok, %{status: 200, body: body}}} <- {:fetch, Fetcher.get(url)},
+ {_, {:ok, results}} <- {:unzip, :zip.unzip(body, [:memory])} do
+ IO.puts("Writing to #{sd}")
+
+ results
+ |> Enum.each(fn {path, contents} ->
+ path = String.replace(to_string(path), ~r/^dist/, "")
+ path = Path.join(sd, path)
+ File.mkdir_p!(Path.dirname(path))
+ File.write!(path, contents)
+ end)
+
+ IO.puts("Successfully downloaded and unpacked the frontend")
+ else
+ {error, _} -> IO.puts("Step failed: #{error}")
+ end
+ end
+end
+
+defmodule Mix.Tasks.Pleroma.Frontend.Fetcher do
+ use Tesla
+ plug(Tesla.Middleware.FollowRedirects)
+
+ adapter(Tesla.Adapter.Httpc)
+end