From f9be962cc59cb5e75c0f50aba99a78f1090c3dad Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Wed, 10 Jan 2024 08:30:49 +0000 Subject: :sparkles: Always run 'gleam build' before starting lustre/try. --- src/http_ffi.erl | 7 +++++-- src/lustre/try.gleam | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/http_ffi.erl b/src/http_ffi.erl index 355fabd..f64c559 100644 --- a/src/http_ffi.erl +++ b/src/http_ffi.erl @@ -1,5 +1,8 @@ -module(http_ffi). --export([serve/3, response_default_headers/0]). +-export([exec/1, serve/3, response_default_headers/0]). + +exec(Command) -> + os:cmd(binary_to_list(Command)). serve({options, Host, Port, IncludeStyles}, OnStart, OnPortTaken) -> {ok, Pattern} = re:compile("name *= *\"(?.+)\""), @@ -16,7 +19,7 @@ serve({options, Host, Port, IncludeStyles}, OnStart, OnPortTaken) -> " Lustre preview server\n", case IncludeStyles of true -> - <<" \n">>; + <<" \n">>; false -> <<"">> end/binary, diff --git a/src/lustre/try.gleam b/src/lustre/try.gleam index 3feef35..177da97 100644 --- a/src/lustre/try.gleam +++ b/src/lustre/try.gleam @@ -39,6 +39,7 @@ pub fn main() { let assert Ok(include_styles) = flag.get_bool(flags, "include-styles") let options = Options(host, port, include_styles) + exec("gleam build --target js") serve(options, on_start(host, _), on_port_taken) }) |> glint.flag("host", host_flag()) @@ -79,8 +80,8 @@ fn on_start(host: String, port: Int) -> Nil { fn on_port_taken(port) -> Nil { io.println( "🚨 Port " - <> ansi.bold(int.to_string(port)) - <> " already in use, using next available port", + <> ansi.bold(int.to_string(port)) + <> " already in use, using next available port", ) } @@ -93,3 +94,7 @@ fn serve( on_start: fn(Int) -> Nil, on_port_taken: fn(Int) -> Nil, ) -> Nil + +@external(erlang, "http_ffi", "exec") +@external(javascript, "node:child_process", "execSync") +fn exec(command: String) -> String -- cgit v1.2.3