Skip to content

Commit

Permalink
Improve UX for warnings arounds doc config and generation (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
starbelly authored Dec 11, 2021
1 parent 11a784a commit 71cb75c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/rebar3_hex_docs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ handle_command(App, State, Repo) ->
end.

do_publish(App, State, Repo) ->
maybe_gen_docs(State, Repo),
AppDir = rebar_app_info:dir(App),
DocDir = resolve_doc_dir(App),
assert_doc_dir(filename:join(AppDir, DocDir)),
AbsDocDir = filename:join(AppDir, DocDir),
maybe_gen_docs(State, Repo, AbsDocDir),
assert_doc_dir(AbsDocDir),
Files = rebar3_hex_file:expand_paths([DocDir], AppDir),
AppDetails = rebar_app_info:app_details(App),
Name = binary_to_list(rebar_app_info:name(App)),
Expand Down Expand Up @@ -203,7 +204,7 @@ resolve_doc_dir(AppInfo) ->
%% ]
%% }.
%% '''
maybe_gen_docs(State, Repo) ->
maybe_gen_docs(State, Repo, DocDir) ->
case doc_opts(State, Repo) of
{ok, #{provider := PrvName}} ->
case providers:get_provider(PrvName, rebar_state:providers(State)) of
Expand All @@ -213,8 +214,10 @@ maybe_gen_docs(State, Repo) ->
gen_docs(State, Prv)
end;
_ ->
Msg = "No valid hex docs configuration found. Docs will will not be generated",
rebar_api:error(Msg, [])
%%% In rebar3 hex 6.11.x docs may be pre-generated, thus we should not warn if
%%% the presence of docs are detected but there is no provider configured.
Msg = "No valid hex docs configuration found. Docs will will not be generated.",
docs_detected(DocDir) orelse rebar_api:error(Msg, [])
end.

doc_opts(State, Repo) ->
Expand All @@ -239,7 +242,10 @@ gen_docs(State, Prv) ->

-spec assert_doc_dir(string()) -> true.
assert_doc_dir(DocDir) ->
filelib:is_file(DocDir ++ "/index.html") orelse missing_doc_abort(DocDir).
docs_detected(DocDir) orelse missing_doc_abort(DocDir).

docs_detected(DocDir) ->
filelib:is_file(DocDir ++ "/index.html").

missing_doc_abort(DocDir) ->
rebar_api:abort( "Docs were not published since they "
Expand Down

0 comments on commit 71cb75c

Please sign in to comment.