-module(eensy_dev_tools@project). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([export/0, flash_esp_32/2, run_local/1, root/0, config/0, type_to_string/1]). -export_type([config/0, interface/0, module_/0, function_/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. -type config() :: {config, binary(), binary(), gleam@dict:dict(binary(), tom:toml())}. -type interface() :: {interface, binary(), binary(), gleam@dict:dict(binary(), module_())}. -type module_() :: {module, gleam@dict:dict(binary(), gleam@package_interface:type()), gleam@dict:dict(binary(), function_())}. -type function_() :: {function, list(gleam@package_interface:type()), gleam@package_interface:type()}. -file("src/eensy_dev_tools/project.gleam", 38). ?DOC(" Generate export erlang-shipment\n"). -spec export() -> {ok, nil} | {error, eensy_dev_tools@error:error()}. export() -> _pipe = eensy_dev_tools_ffi:exec( <<"gleam"/utf8>>, [<<"export"/utf8>>, <<"erlang-shipment"/utf8>>], <<"."/utf8>> ), _pipe@1 = gleam@result:map_error( _pipe, fun(Err) -> {build_error, gleam@pair:second(Err)} end ), gleam@result:replace(_pipe@1, nil). -file("src/eensy_dev_tools/project.gleam", 44). -spec flash_esp_32(binary(), binary()) -> {ok, nil} | {error, eensy_dev_tools@error:error()}. flash_esp_32(Project_name, Port) -> Args = [<<"--chip"/utf8>>, <<"auto"/utf8>>, <<"--port"/utf8>>, Port, <<"--baud"/utf8>>, <<"921600"/utf8>>, <<"--before"/utf8>>, <<"default_reset"/utf8>>, <<"--after"/utf8>>, <<"hard_reset"/utf8>>, <<"write_flash"/utf8>>, <<"-u"/utf8>>, <<"--flash_mode"/utf8>>, <<"keep"/utf8>>, <<"--flash_freq"/utf8>>, <<"keep"/utf8>>, <<"--flash_size"/utf8>>, <<"detect"/utf8>>, <<"0x210000"/utf8>>, <<<<"./build/.atomvm/"/utf8, Project_name/binary>>/binary, ".release.avm"/utf8>>], _pipe = eensy_dev_tools_ffi:exec(<<"esptool.py"/utf8>>, Args, <<"."/utf8>>), _pipe@1 = gleam@result:map_error( _pipe, fun(Err) -> {build_error, gleam@pair:second(Err)} end ), gleam@result:replace(_pipe@1, nil). -file("src/eensy_dev_tools/project.gleam", 72). -spec run_local(binary()) -> {ok, nil} | {error, eensy_dev_tools@error:error()}. run_local(Project_name) -> _pipe = eensy_dev_tools_ffi:exec( <<"atomvm "/utf8>>, [<<<<"./build/.atomvm/"/utf8, Project_name/binary>>/binary, ".release.avm"/utf8>>], <<"."/utf8>> ), _pipe@1 = gleam@result:map_error( _pipe, fun(Err) -> {build_error, gleam@pair:second(Err)} end ), gleam@result:replace(_pipe@1, nil). -file("src/eensy_dev_tools/project.gleam", 108). -spec find_root(binary()) -> binary(). find_root(Path) -> Toml = filepath:join(Path, <<"gleam.toml"/utf8>>), case simplifile_erl:is_file(Toml) of {ok, false} -> find_root(filepath:join(<<".."/utf8>>, Path)); {error, _} -> find_root(filepath:join(<<".."/utf8>>, Path)); {ok, true} -> Path end. -file("src/eensy_dev_tools/project.gleam", 104). ?DOC( " Finds the path leading to the project's root folder. This recursively walks\n" " up from the current directory until it finds a `gleam.toml`.\n" ). -spec root() -> binary(). root() -> find_root(<<"."/utf8>>). -file("src/eensy_dev_tools/project.gleam", 82). ?DOC(" Read the project configuration in the `gleam.toml` file.\n"). -spec config() -> {ok, config()} | {error, eensy_dev_tools@error:error()}. config() -> Configuration_path = filepath:join(root(), <<"gleam.toml"/utf8>>), _assert_subject = simplifile:read(Configuration_path), {ok, Configuration} = 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 => <<"eensy_dev_tools/project"/utf8>>, function => <<"config"/utf8>>, line => 91}) end, _assert_subject@1 = tom:parse(Configuration), {ok, Toml} = case _assert_subject@1 of {ok, _} -> _assert_subject@1; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@1, module => <<"eensy_dev_tools/project"/utf8>>, function => <<"config"/utf8>>, line => 92}) end, _assert_subject@2 = tom:get_string(Toml, [<<"name"/utf8>>]), {ok, Name} = case _assert_subject@2 of {ok, _} -> _assert_subject@2; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@2, module => <<"eensy_dev_tools/project"/utf8>>, function => <<"config"/utf8>>, line => 93}) end, _assert_subject@3 = tom:get_string(Toml, [<<"version"/utf8>>]), {ok, Version} = case _assert_subject@3 of {ok, _} -> _assert_subject@3; _assert_fail@3 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@3, module => <<"eensy_dev_tools/project"/utf8>>, function => <<"config"/utf8>>, line => 94}) end, {ok, {config, Name, Version, Toml}}. -file("src/eensy_dev_tools/project.gleam", 117). -spec type_to_string(gleam@package_interface:type()) -> binary(). type_to_string(Type_) -> case Type_ of {tuple, Elements} -> Elements@1 = gleam@list:map(Elements, fun type_to_string/1), <<<<"#("/utf8, (gleam@string:join(Elements@1, <<", "/utf8>>))/binary>>/binary, ")"/utf8>>; {fn, Params, Return} -> Params@1 = gleam@list:map(Params, fun type_to_string/1), Return@1 = type_to_string(Return), <<<<<<"fn("/utf8, (gleam@string:join(Params@1, <<", "/utf8>>))/binary>>/binary, ") -> "/utf8>>/binary, Return@1/binary>>; {named, Name, _, _, []} -> Name; {named, Name@1, _, _, Params@2} -> Params@3 = gleam@list:map(Params@2, fun type_to_string/1), <<<<<>/binary, (gleam@string:join(Params@3, <<", "/utf8>>))/binary>>/binary, ")"/utf8>>; {variable, Id} -> <<"a_"/utf8, (erlang:integer_to_binary(Id))/binary>> end.