aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-01-10 08:30:49 +0000
committerHayleigh Thompson <me@hayleigh.dev>2024-01-10 08:30:49 +0000
commitf9be962cc59cb5e75c0f50aba99a78f1090c3dad (patch)
treec1b34691cdf0b448b0addcf0e96b8ed636a58e48
parent57d124d9c0b5c8bbf5157b407599f38cb466965d (diff)
downloadlustre-f9be962cc59cb5e75c0f50aba99a78f1090c3dad.tar.gz
lustre-f9be962cc59cb5e75c0f50aba99a78f1090c3dad.zip
:sparkles: Always run 'gleam build' before starting lustre/try.
-rw-r--r--src/http_ffi.erl7
-rw-r--r--src/lustre/try.gleam9
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 *= *\"(?<Name>.+)\""),
@@ -16,7 +19,7 @@ serve({options, Host, Port, IncludeStyles}, OnStart, OnPortTaken) ->
" <title>Lustre preview server</title>\n",
case IncludeStyles of
true ->
- <<" <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/lustre-labs/ui/priv/styles.css\">\n">>;
+ <<" <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/lustre-labs/ui/priv/styles.css\">\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