Current section
Files
Jump to
Current section
Files
src/go_over@workspace.erl
-module(go_over@workspace).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/go_over/workspace.gleam").
-export([discover/2, discover_or_error/2]).
-export_type([discover_result/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).
-type discover_result() :: {discover_result, list(binary()), list(binary())}.
-file("src/go_over/workspace.gleam", 13).
?DOC(false).
-spec is_project_dir(binary()) -> boolean().
is_project_dir(Dir) ->
Gleam_toml = filepath:join(Dir, <<"gleam.toml"/utf8>>),
Manifest = filepath:join(Dir, <<"manifest.toml"/utf8>>),
case {simplifile_erl:is_file(Gleam_toml), simplifile_erl:is_file(Manifest)} of
{{ok, true}, {ok, true}} ->
true;
{_, _} ->
false
end.
-file("src/go_over/workspace.gleam", 23).
?DOC(false).
-spec should_skip(binary()) -> boolean().
should_skip(Name) ->
gleam_stdlib:string_starts_with(Name, <<"."/utf8>>) orelse gleam@list:contains(
[<<"build"/utf8>>,
<<"deps"/utf8>>,
<<"node_modules"/utf8>>,
<<".go-over"/utf8>>,
<<".git"/utf8>>],
Name
).
-file("src/go_over/workspace.gleam", 27).
?DOC(false).
-spec find_projects_unlimited(binary()) -> list(binary()).
find_projects_unlimited(Dir) ->
case is_project_dir(Dir) of
true ->
[Dir];
false ->
case simplifile_erl:read_directory(Dir) of
{ok, Names} ->
_pipe = Names,
_pipe@1 = gleam@list:filter(
_pipe,
fun(Name) -> not should_skip(Name) end
),
gleam@list:flat_map(
_pipe@1,
fun(Name@1) ->
find_projects_unlimited(filepath:join(Dir, Name@1))
end
);
{error, _} ->
[]
end
end.
-file("src/go_over/workspace.gleam", 43).
?DOC(false).
-spec has_project_descendant(binary()) -> boolean().
has_project_descendant(Dir) ->
not gleam@list:is_empty(find_projects_unlimited(Dir)).
-file("src/go_over/workspace.gleam", 47).
?DOC(false).
-spec do_discover(binary(), integer(), integer(), list(binary())) -> {list(binary()),
list(binary())}.
do_discover(Dir, Depth, Max_depth, Skipped) ->
case is_project_dir(Dir) of
true ->
{[Dir], Skipped};
false ->
case Depth >= Max_depth of
true ->
Skipped@1 = case has_project_descendant(Dir) of
true ->
lists:append(Skipped, find_projects_unlimited(Dir));
false ->
Skipped
end,
{[], Skipped@1};
false ->
case simplifile_erl:read_directory(Dir) of
{ok, Names} ->
_pipe = Names,
_pipe@1 = gleam@list:filter(
_pipe,
fun(Name) -> not should_skip(Name) end
),
gleam@list:fold(
_pipe@1,
{[], Skipped},
fun(Acc, Name@1) ->
{Projects, Skipped@2} = Acc,
Child = filepath:join(Dir, Name@1),
{Child_projects, Child_skipped} = do_discover(
Child,
Depth + 1,
Max_depth,
[]
),
{lists:append(Projects, Child_projects),
lists:append(Skipped@2, Child_skipped)}
end
);
{error, _} ->
{[], Skipped}
end
end
end.
-file("src/go_over/workspace.gleam", 85).
?DOC(false).
-spec discover(binary(), integer()) -> discover_result().
discover(Scan_root, Max_depth) ->
{Projects, Skipped} = do_discover(Scan_root, 0, Max_depth, []),
{discover_result,
begin
_pipe = Projects,
gleam@list:sort(
_pipe,
fun(A, B) -> case gleam@string:compare(A, B) of
eq ->
eq;
lt ->
lt;
gt ->
gt
end end
)
end,
begin
_pipe@1 = Skipped,
_pipe@2 = gleam@list:unique(_pipe@1),
gleam@list:sort(
_pipe@2,
fun(A@1, B@1) -> case gleam@string:compare(A@1, B@1) of
eq ->
eq;
lt ->
lt;
gt ->
gt
end end
)
end}.
-file("src/go_over/workspace.gleam", 109).
?DOC(false).
-spec discover_or_error(binary(), integer()) -> {ok, discover_result()} |
{error, binary()}.
discover_or_error(Scan_root, Max_depth) ->
case discover(Scan_root, Max_depth) of
{discover_result, [], _} ->
{error, <<"no gleam projects found under "/utf8, Scan_root/binary>>};
Result ->
{ok, Result}
end.