Current section
Files
Jump to
Current section
Files
src/gleative.erl
-module(gleative).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([main/0]).
-spec build_js() -> nil.
build_js() ->
Res = shellout:command(
<<"gleam"/utf8>>,
[<<"build"/utf8>>, <<"--target"/utf8>>, <<"javascript"/utf8>>],
<<"."/utf8>>,
[]
),
case gleam@result:is_error(Res) of
true ->
gleam@io:println(<<"Failed to execute gleam"/utf8>>);
false ->
nil
end.
-spec write_config() -> nil.
write_config() ->
_assert_subject = simplifile:read(<<"./gleam.toml"/utf8>>),
{ok, Project_toml} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"gleative"/utf8>>,
function => <<"write_config"/utf8>>,
line => 46})
end,
_assert_subject@1 = tom:parse(Project_toml),
{ok, Parsed} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"gleative"/utf8>>,
function => <<"write_config"/utf8>>,
line => 47})
end,
_assert_subject@2 = tom:get_string(Parsed, [<<"name"/utf8>>]),
{ok, Name} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@2,
module => <<"gleative"/utf8>>,
function => <<"write_config"/utf8>>,
line => 48})
end,
Compile_content = <<<<<<<<"import {main} from \"./"/utf8, Name/binary>>/binary,
"/"/utf8>>/binary,
Name/binary>>/binary,
".mjs\";main();"/utf8>>,
Res = begin
_pipe = Compile_content,
simplifile:write(<<"./build/dev/javascript/compile.js"/utf8>>, _pipe)
end,
case gleam@result:is_error(Res) of
true ->
gleam@io:println(<<"Failed to write file"/utf8>>);
false ->
nil
end,
Deno_config = <<"{\"compilerOptions\":{\"noImplicitAny\":false,\"strict\":false}}"/utf8>>,
Res@1 = begin
_pipe@1 = Deno_config,
simplifile:write(<<"./build/dev/javascript/deno.json"/utf8>>, _pipe@1)
end,
case gleam@result:is_error(Res@1) of
true ->
gleam@io:println(<<"Failed to write file"/utf8>>);
false ->
nil
end.
-spec compile_native(spinner:spinner()) -> list(nil).
compile_native(Spinner) ->
_assert_subject = simplifile:read(<<"./gleative.toml"/utf8>>),
{ok, Gleative_toml} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"gleative"/utf8>>,
function => <<"compile_native"/utf8>>,
line => 76})
end,
_assert_subject@1 = tom:parse(Gleative_toml),
{ok, Parsed} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"gleative"/utf8>>,
function => <<"compile_native"/utf8>>,
line => 77})
end,
_assert_subject@2 = tom:get_array(Parsed, [<<"targets"/utf8>>]),
{ok, Targets} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@2,
module => <<"gleative"/utf8>>,
function => <<"compile_native"/utf8>>,
line => 78})
end,
_pipe = gleam@iterator:from_list(Targets),
_pipe@1 = gleam@iterator:map(
_pipe,
fun(Target_toml) ->
Target@1 = case Target_toml of
{string, Target} ->
Target;
_ ->
gleam@io:println(<<"Not a string"/utf8>>),
<<""/utf8>>
end,
spinner:set_text(
Spinner,
<<<<"Compiling target "/utf8, Target@1/binary>>/binary,
" with deno..."/utf8>>
),
Res = shellout:command(
<<"deno"/utf8>>,
[<<"compile"/utf8>>,
<<"--no-check"/utf8>>,
<<"-A"/utf8>>,
<<"--config"/utf8>>,
<<"./deno.json"/utf8>>,
<<"--target"/utf8>>,
Target@1,
<<"--output"/utf8>>,
<<<<"../../gleative_out/"/utf8, Target@1/binary>>/binary,
"/out"/utf8>>,
<<"./compile.js"/utf8>>],
<<"./build/dev/javascript"/utf8>>,
[]
),
case gleam@result:is_error(Res) of
true ->
gleam@io:println(
<<"Failed to execute deno for target "/utf8,
Target@1/binary>>
);
false ->
nil
end
end
),
gleam@iterator:to_list(_pipe@1).
-spec main() -> nil.
main() ->
Spinner = begin
_pipe = spinner:new(<<"Gleative compile"/utf8>>),
_pipe@1 = spinner:with_colour(_pipe, fun gleam_community@ansi:blue/1),
spinner:start(_pipe@1)
end,
spinner:set_text(
Spinner,
<<"Compiling gleam project to javascript..."/utf8>>
),
build_js(),
write_config(),
compile_native(Spinner),
spinner:stop(Spinner),
_pipe@2 = <<"Finished compilation! You can find your native executables in ./build/gleative_out"/utf8>>,
_pipe@3 = gleam_community@ansi:green(_pipe@2),
gleam@io:println(_pipe@3).