Current section
Files
Jump to
Current section
Files
src/runetracer.erl
-module(runetracer).
-compile([no_auto_import, nowarn_unused_vars]).
-export([main/0]).
-spec sort_imports(list(binary())) -> {ok, list(binary())} | {error, nil}.
sort_imports(Imports) ->
gleam@bool:guard(
begin
_pipe@2 = gleam@list:filter(
Imports,
fun(X) ->
begin
_pipe = X,
_pipe@1 = gleam@string:split(_pipe, <<" "/utf8>>),
gleam@list:length(_pipe@1)
end
=:= 1
end
),
_pipe@3 = gleam@list:is_empty(_pipe@2),
gleam@bool:negate(_pipe@3)
end,
{error, nil},
fun() ->
_pipe@10 = gleam@list:sort(
Imports,
fun(X@1, Y) ->
_assert_subject = begin
_pipe@4 = X@1,
_pipe@5 = gleam@string:split(_pipe@4, <<" "/utf8>>),
_pipe@6 = gleam@list:at(_pipe@5, 1),
gleam@result:map(_pipe@6, fun gleam@string:trim/1)
end,
{ok, X@2} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"runetracer"/utf8>>,
function => <<"sort_imports"/utf8>>,
line => 54})
end,
_assert_subject@1 = begin
_pipe@7 = Y,
_pipe@8 = gleam@string:split(_pipe@7, <<" "/utf8>>),
_pipe@9 = gleam@list:at(_pipe@8, 1),
gleam@result:map(_pipe@9, fun gleam@string:trim/1)
end,
{ok, Y@1} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"runetracer"/utf8>>,
function => <<"sort_imports"/utf8>>,
line => 60})
end,
gleam@bool:guard(
gleam@string:starts_with(X@2, <<"gleam/"/utf8>>)
andalso gleam@string:starts_with(Y@1, <<"gleam/"/utf8>>),
gleam@string:compare(X@2, Y@1),
fun() ->
gleam@bool:guard(
gleam@string:starts_with(X@2, <<"gleam/"/utf8>>),
lt,
fun() ->
gleam@bool:guard(
gleam@string:starts_with(
Y@1,
<<"gleam/"/utf8>>
),
gt,
fun() ->
gleam@string:compare(X@2, Y@1)
end
)
end
)
end
)
end
),
{ok, _pipe@10}
end
).
-spec sort_file(binary()) -> {ok, binary()} | {error, nil}.
sort_file(File_contents) ->
Lines = gleam@string:split(File_contents, <<"\n"/utf8>>),
{To_sort, Rest} = gleam@list:split_while(
Lines,
fun(Line) ->
_pipe = Line,
_pipe@1 = gleam@string:trim(_pipe),
(fun(S) ->
gleam@string:starts_with(S, <<"import"/utf8>>)
orelse begin
_pipe@2 = not gleam@string:is_empty(S),
gleam@bool:negate(_pipe@2)
end
end)(_pipe@1)
end
),
_pipe@3 = To_sort,
_pipe@5 = gleam@list:filter(
_pipe@3,
fun(X) ->
_pipe@4 = gleam@string:is_empty(X),
gleam@bool:negate(_pipe@4)
end
),
_pipe@6 = sort_imports(_pipe@5),
gleam@result:map(
_pipe@6,
fun(X@1) ->
_pipe@7 = gleam@list:append(X@1, [<<""/utf8>> | Rest]),
gleam@string:join(_pipe@7, <<"\n"/utf8>>)
end
).
-spec main() -> nil.
main() ->
Path = case '.@sorting.mjs':'getArgs'() of
[Arg | _] ->
Arg;
_ ->
<<"src/"/utf8>>
end,
case '.@sorting.mjs':'dirExists'(Path) of
false ->
gleam@io:println(<<"Directory not found: "/utf8, Path/binary>>),
'.@sorting.mjs':exit(1),
nil;
true ->
nil
end,
'.@sorting.mjs':sort(Path, fun sort_file/1).