-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()}. -file("/Users/darky/Projects/cleam/src/internal/fs.gleam", 23). -spec files_paths(files_dir()) -> list(file_path()). files_paths(Dir) -> {files_dir, Dir@1} = Dir, _pipe = fswalk:builder(), _pipe@1 = fswalk:with_path(_pipe, Dir@1), _pipe@2 = fswalk:walk(_pipe@1), _pipe@3 = gleam@yielder:filter( _pipe@2, fun(Entry_result) -> case Entry_result of {ok, {entry, Path, {stat, Is_dir}}} -> (Is_dir =:= false) andalso gleam_stdlib:string_ends_with( Path, <<".gleam"/utf8>> ); _ -> false end end ), _pipe@4 = gleam@yielder:map( _pipe@3, fun(Entry_result@1) -> {ok, {entry, Path@1, _}} = case Entry_result@1 of {ok, {entry, _, _}} -> Entry_result@1; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"internal/fs"/utf8>>, function => <<"files_paths"/utf8>>, line => 36}) end, {file_path, Path@1} end ), gleam@yielder:to_list(_pipe@4). -file("/Users/darky/Projects/cleam/src/internal/fs.gleam", 42). -spec files_contents(list(file_path())) -> list(file_content()). files_contents(Files_paths) -> gleam@list:map( Files_paths, fun(Path) -> {file_path, Path@1} = Path, _assert_subject = simplifile:read(Path@1), {ok, Content} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail, module => <<"internal/fs"/utf8>>, function => <<"files_contents"/utf8>>, line => 45}) end, {file_content, Content} end ). -file("/Users/darky/Projects/cleam/src/internal/fs.gleam", 49). -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} = Files_dir, {file_path, File_path@1} = File_path, _pipe = File_path@1, _pipe@1 = gleam@string:replace( _pipe, <>, <<""/utf8>> ), _pipe@2 = gleam@string:replace(_pipe@1, <<".gleam"/utf8>>, <<""/utf8>>), {module_full_name, _pipe@2}.