-module(builder@internal@util). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/builder/internal/util.gleam"). -export([find_project_root_path/1, find_current_project_root_path/0, scan_walk/1, trim_prefix/2, trim_sufix/2]). -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/builder/internal/util.gleam", 16). ?DOC(false). -spec find_project_root_path_loop(binary()) -> binary(). find_project_root_path_loop(Path) -> case Path of <<""/utf8>> -> erlang:error(#{gleam_error => panic, message => <<"gleam project directory couldn't be found"/utf8>>, file => <>, module => <<"builder/internal/util"/utf8>>, function => <<"find_project_root_path_loop"/utf8>>, line => 19}); _ -> case simplifile_erl:is_file( filepath:join(Path, <<"gleam.toml"/utf8>>) ) of {ok, true} -> Path; _ -> find_project_root_path_loop(filepath:directory_name(Path)) end end. -file("src/builder/internal/util.gleam", 12). ?DOC(false). -spec find_project_root_path(binary()) -> binary(). find_project_root_path(Path) -> find_project_root_path_loop(Path). -file("src/builder/internal/util.gleam", 6). ?DOC(false). -spec find_current_project_root_path() -> binary(). find_current_project_root_path() -> Current_directory@1 = case simplifile:current_directory() of {ok, Current_directory} -> Current_directory; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"current directory couldn't be fetched"/utf8>>, file => <>, module => <<"builder/internal/util"/utf8>>, function => <<"find_current_project_root_path"/utf8>>, line => 7, value => _assert_fail, start => 127, 'end' => 192, pattern_start => 138, pattern_end => 159}) end, find_project_root_path(Current_directory@1). -file("src/builder/internal/util.gleam", 29). ?DOC(false). -spec scan_walk(binary()) -> list(binary()). scan_walk(Path) -> case filepath:is_absolute(Path) of true -> nil; false -> erlang:error(#{gleam_error => assert, message => <<"scan_walk should always start with a absolute path"/utf8>>, file => <>, module => <<"builder/internal/util"/utf8>>, function => <<"scan_walk"/utf8>>, line => 30, kind => function_call, arguments => [#{kind => expression, value => Path, start => 797, 'end' => 801 }], start => 769, 'end' => 802, expression_start => 776}) end, case simplifile_erl:is_file(Path) of {ok, true} -> [Path]; _ -> Paths = case simplifile_erl:read_directory(Path) of {ok, Files} -> Files; {error, enoent} -> []; {error, _} -> erlang:error(#{gleam_error => panic, message => (<<"couldn't read directory: "/utf8, Path/binary>>), file => <>, module => <<"builder/internal/util"/utf8>>, function => <<"scan_walk"/utf8>>, line => 42}) end, gleam@list:flat_map( Paths, fun(Name) -> scan_walk(filepath:join(Path, Name)) end ) end. -file("src/builder/internal/util.gleam", 50). ?DOC(false). -spec trim_prefix(binary(), binary()) -> binary(). trim_prefix(String, Prefix) -> case gleam_stdlib:string_starts_with(String, Prefix) of true -> gleam@string:drop_start(String, string:length(Prefix)); false -> String end. -file("src/builder/internal/util.gleam", 57). ?DOC(false). -spec trim_sufix(binary(), binary()) -> binary(). trim_sufix(String, Prefix) -> case gleam_stdlib:string_ends_with(String, Prefix) of true -> gleam@string:drop_end(String, string:length(Prefix)); false -> String end.