Current section
Files
Jump to
Current section
Files
src/internal@fs.erl
-module(internal@fs).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([files_paths/1, files_contents/1, file_path_to_module_full_name/2]).
-export_type([file_path/0, file_content/0, files_dir/0, module_full_name/0]).
-type file_path() :: {file_path, binary()}.
-type file_content() :: {file_content, binary()}.
-type files_dir() :: {files_dir, binary()}.
-type module_full_name() :: {module_full_name, binary()}.
-spec files_paths(files_dir()) -> list(file_path()).
files_paths(Dir) ->
{files_dir, Dir@1} = case Dir of
{files_dir, _} -> Dir;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"internal/fs"/utf8>>,
function => <<"files_paths"/utf8>>,
line => 24})
end,
_pipe = fswalk:builder(),
_pipe@1 = fswalk:with_path(_pipe, Dir@1),
_pipe@2 = fswalk:walk(_pipe@1),
_pipe@3 = gleam@iterator:filter(
_pipe@2,
fun(Entry_result) -> case Entry_result of
{ok, {entry, Path, {stat, Is_dir}}} ->
(Is_dir =:= false) andalso gleam@string:ends_with(
Path,
<<".gleam"/utf8>>
);
_ ->
false
end end
),
_pipe@4 = gleam@iterator:map(
_pipe@3,
fun(Entry_result@1) ->
{ok, {entry, Path@1, _}} = case Entry_result@1 of
{ok, {entry, _, _}} -> Entry_result@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"internal/fs"/utf8>>,
function => <<"files_paths"/utf8>>,
line => 36})
end,
{file_path, Path@1}
end
),
gleam@iterator:to_list(_pipe@4).
-spec files_contents(list(file_path())) -> list(file_content()).
files_contents(Files_paths) ->
gleam@list:map(
Files_paths,
fun(Path) ->
{file_path, Path@1} = case Path of
{file_path, _} -> Path;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"internal/fs"/utf8>>,
function => <<"files_contents"/utf8>>,
line => 44})
end,
_assert_subject = simplifile:read(Path@1),
{ok, Content} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"internal/fs"/utf8>>,
function => <<"files_contents"/utf8>>,
line => 45})
end,
{file_content, Content}
end
).
-spec file_path_to_module_full_name(files_dir(), file_path()) -> module_full_name().
file_path_to_module_full_name(Files_dir, File_path) ->
{files_dir, Files_dir@1} = case Files_dir of
{files_dir, _} -> Files_dir;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"internal/fs"/utf8>>,
function => <<"file_path_to_module_full_name"/utf8>>,
line => 50})
end,
{file_path, File_path@1} = case File_path of
{file_path, _} -> File_path;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"internal/fs"/utf8>>,
function => <<"file_path_to_module_full_name"/utf8>>,
line => 51})
end,
_pipe = File_path@1,
_pipe@1 = gleam@string:replace(
_pipe,
<<Files_dir@1/binary, "/"/utf8>>,
<<""/utf8>>
),
_pipe@2 = gleam@string:replace(_pipe@1, <<".gleam"/utf8>>, <<""/utf8>>),
{module_full_name, _pipe@2}.