Current section

Files

Jump to
parrot src parrot@internal@project.erl
Raw

src/parrot@internal@project.erl

-module(parrot@internal@project).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([root/0, version/0, src/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/parrot/internal/project.gleam", 27).
?DOC(false).
-spec find_root(binary()) -> binary().
find_root(Path) ->
Toml = filepath:join(Path, <<"gleam.toml"/utf8>>),
case simplifile_erl:is_file(Toml) of
{ok, false} ->
find_root(filepath:join(<<".."/utf8>>, Path));
{error, _} ->
find_root(filepath:join(<<".."/utf8>>, Path));
{ok, true} ->
Path
end.
-file("src/parrot/internal/project.gleam", 19).
?DOC(false).
-spec root() -> binary().
root() ->
find_root(<<"."/utf8>>).
-file("src/parrot/internal/project.gleam", 10).
?DOC(false).
-spec version() -> {ok, binary()} | {error, nil}.
version() ->
Configuration_path = filepath:join(root(), <<"gleam.toml"/utf8>>),
parrot@internal@lib:try_nil(
simplifile:read(Configuration_path),
fun(Configuration) ->
parrot@internal@lib:try_nil(
tom:parse(Configuration),
fun(Toml) ->
parrot@internal@lib:try_nil(
tom:get_string(Toml, [<<"version"/utf8>>]),
fun(Name) -> {ok, Name} end
)
end
)
end
).
-file("src/parrot/internal/project.gleam", 23).
?DOC(false).
-spec src() -> binary().
src() ->
filepath:join(root(), <<"src"/utf8>>).