Packages

A gleamy app framework.

Current section

Files

Jump to
pane_gleam src commands@build.erl
Raw

src/commands@build.erl

-module(commands@build).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/commands/build.gleam").
-export([main/0]).
-file("src/commands/build.gleam", 11).
-spec download_rust_bin() -> nil.
download_rust_bin() ->
Binary = helpers@http:download(
<<"https://github.com/Thebugcanfly13/pane/releases/download/rust/pane-webview"/utf8>>
),
case simplifile_erl:write_bits(<<"output/pane/pane-webview"/utf8>>, Binary) of
{ok, nil} ->
nil;
{error, E} ->
gleam_stdlib:println(
<<(gleam_community@ansi:red(<<"Error: "/utf8>>))/binary,
(simplifile:describe_error(E))/binary>>
),
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"download_rust_bin"/utf8>>,
line => 17})
end.
-file("src/commands/build.gleam", 22).
-spec verify_rust_bin() -> nil.
verify_rust_bin() ->
case simplifile_erl:is_file(<<"output/pane/pane-webview"/utf8>>) of
{ok, true} ->
nil;
{ok, false} ->
download_rust_bin();
{error, E} ->
gleam_stdlib:println(
<<(gleam_community@ansi:red(<<"Error: "/utf8>>))/binary,
(simplifile:describe_error(E))/binary>>
),
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"verify_rust_bin"/utf8>>,
line => 28})
end.
-file("src/commands/build.gleam", 33).
-spec copy_content() -> nil.
copy_content() ->
case simplifile:copy_directory(
<<"priv/static/"/utf8>>,
<<"priv/pane"/utf8>>
) of
{ok, nil} ->
nil;
{error, E} ->
gleam_stdlib:println(
<<(gleam_community@ansi:red(<<"Error: "/utf8>>))/binary,
(simplifile:describe_error(E))/binary>>
),
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"copy_content"/utf8>>,
line => 38})
end.
-file("src/commands/build.gleam", 43).
-spec get_gleam_toml() -> binary().
get_gleam_toml() ->
case simplifile:read(<<"gleam.toml"/utf8>>) of
{ok, Content} ->
Content;
{error, E} ->
gleam_stdlib:println(
<<(gleam_community@ansi:red(<<"Error: "/utf8>>))/binary,
(simplifile:describe_error(E))/binary>>
),
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"get_gleam_toml"/utf8>>,
line => 48})
end.
-file("src/commands/build.gleam", 53).
-spec get_project_name() -> binary().
get_project_name() ->
Parsed@1 = case tom:parse(get_gleam_toml()) of
{ok, Parsed} -> Parsed;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"get_project_name"/utf8>>,
line => 54,
value => _assert_fail,
start => 1224,
'end' => 1275,
pattern_start => 1235,
pattern_end => 1245})
end,
case tom:get_string(Parsed@1, [<<"name"/utf8>>]) of
{ok, Name} ->
Name;
{error, _} ->
gleam_stdlib:println(
<<(gleam_community@ansi:red(<<"Error: "/utf8>>))/binary,
"Couldn't find project name."/utf8>>
),
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"get_project_name"/utf8>>,
line => 59})
end.
-file("src/commands/build.gleam", 64).
-spec compile_escript() -> nil.
compile_escript() ->
_ = ffi:cmd(<<"gleam export escript"/utf8>>).
-file("src/commands/build.gleam", 68).
-spec move_escript() -> nil.
move_escript() ->
case simplifile:copy_file(
get_project_name(),
<<"priv/pane/"/utf8, (get_project_name())/binary>>
) of
{ok, nil} ->
nil;
{error, E} ->
gleam_stdlib:println(
<<(gleam_community@ansi:red(<<"Error: "/utf8>>))/binary,
(simplifile:describe_error(E))/binary>>
),
erlang:error(#{gleam_error => panic,
message => <<"`panic` expression evaluated."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"commands/build"/utf8>>,
function => <<"move_escript"/utf8>>,
line => 73})
end.
-file("src/commands/build.gleam", 78).
-spec compress() -> nil.
compress() ->
ffi:cmd(<<"zip -r priv/output/pane.zip priv/pane/"/utf8>>).
-file("src/commands/build.gleam", 82).
-spec main() -> nil.
main() ->
gleam_stdlib:println(gleam_community@ansi:blue(<<"Building..."/utf8>>)),
copy_content(),
verify_rust_bin(),
compile_escript(),
move_escript(),
compress(),
gleam_stdlib:println(
gleam_community@ansi:green(
<<"Finished building. Output is ./priv/output/pane.zip"/utf8>>
)
).