mix docs generates config.md
authorAlex S <alex.strizhakov@gmail.com>
Fri, 30 Aug 2019 10:22:21 +0000 (13:22 +0300)
committerAlex S <alex.strizhakov@gmail.com>
Wed, 11 Sep 2019 06:25:33 +0000 (09:25 +0300)
lib/mix/tasks/pleroma/docs.ex [new file with mode: 0644]
mix.exs

diff --git a/lib/mix/tasks/pleroma/docs.ex b/lib/mix/tasks/pleroma/docs.ex
new file mode 100644 (file)
index 0000000..5ae3b87
--- /dev/null
@@ -0,0 +1,40 @@
+defmodule Mix.Tasks.Pleroma.Docs do
+  use Mix.Task
+  import Mix.Pleroma
+
+  @shortdoc "Generates docs from descriptions.exs"
+  @moduledoc """
+  Generates docs from `descriptions.exs`.
+
+  Supports two formats: `markdown` and `json`.
+
+  ## Generate markdown docs
+
+  `mix pleroma.docs`
+
+  ## Generate json docs
+
+  `mix pleroma.docs json`s
+  """
+
+  def run(["json"]) do
+    do_run(Pleroma.Docs.JSON)
+  end
+
+  def run(_) do
+    do_run(Pleroma.Docs.Markdown)
+  end
+
+  defp do_run(implementation) do
+    start_pleroma()
+    descriptions = Config.Reader.read!("config/description.exs")
+
+    {:ok, file_path} =
+      Pleroma.Docs.Formatter.process(
+        implementation,
+        descriptions[:pleroma][:config_description]
+      )
+
+    Mix.shell().info([:green, "Markdown docs successfully generated to #{file_path}."])
+  end
+end
diff --git a/mix.exs b/mix.exs
index 3170d6f2d7ca8413660297439c3fbc092569a458..c52ab08b0193a4359e1bd39620ddf5d23c314dde 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -172,7 +172,8 @@ defmodule Pleroma.Mixfile do
       "ecto.rollback": ["pleroma.ecto.rollback"],
       "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
       "ecto.reset": ["ecto.drop", "ecto.setup"],
-      test: ["ecto.create --quiet", "ecto.migrate", "test"]
+      test: ["ecto.create --quiet", "ecto.migrate", "test"],
+      docs: ["pleroma.docs", "docs"]
     ]
   end