2019-08-30 12:22:21 +02:00
|
|
|
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`.
|
|
|
|
|
2019-08-30 18:14:01 +02:00
|
|
|
## Generate Markdown docs
|
2019-08-30 12:22:21 +02:00
|
|
|
|
|
|
|
`mix pleroma.docs`
|
|
|
|
|
2019-08-30 18:14:01 +02:00
|
|
|
## Generate JSON docs
|
2019-08-30 12:22:21 +02:00
|
|
|
|
2019-08-30 18:59:13 +02:00
|
|
|
`mix pleroma.docs json`
|
2019-08-30 12:22:21 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
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()
|
2019-08-30 13:27:55 +02:00
|
|
|
{descriptions, _paths} = Mix.Config.eval!("config/description.exs")
|
2019-08-30 12:22:21 +02:00
|
|
|
|
|
|
|
{:ok, file_path} =
|
2019-08-30 18:14:01 +02:00
|
|
|
Pleroma.Docs.Generator.process(
|
2019-08-30 12:22:21 +02:00
|
|
|
implementation,
|
|
|
|
descriptions[:pleroma][:config_description]
|
|
|
|
)
|
|
|
|
|
2019-09-03 11:31:43 +02:00
|
|
|
type = if implementation == Pleroma.Docs.Markdown, do: "Markdown", else: "JSON"
|
|
|
|
|
|
|
|
Mix.shell().info([:green, "#{type} docs successfully generated to #{file_path}."])
|
2019-08-30 12:22:21 +02:00
|
|
|
end
|
|
|
|
end
|