Current section
Files
Jump to
Current section
Files
src/dev_tools@internals@structure.erl
-module(dev_tools@internals@structure).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([create/0, command/0]).
-spec check_file_exist(binary()) -> boolean().
check_file_exist(Path) ->
case simplifile_erl:is_file(Path) of
{ok, true} ->
true;
{ok, false} ->
false;
{error, _} ->
false
end.
-spec create_html(binary(), binary(), binary()) -> dev_tools@internals@cli:cli(nil).
create_html(Outdir, Filename, Html) ->
dev_tools@internals@cli:log(
<<"Creating "/utf8, Filename/binary>>,
fun() ->
Outfile = filepath:join(Outdir, Filename),
case check_file_exist(Outfile) of
true ->
dev_tools@internals@cli:success(
<<Outfile/binary, " already exist"/utf8>>,
fun() -> dev_tools@internals@cli:return(nil) end
);
false ->
Write_result = begin
_pipe = simplifile:write(Outfile, Html),
gleam@result:map_error(
_pipe,
fun(_capture) ->
{cannot_write_file,
_capture,
filepath:join(Outdir, Outfile)}
end
)
end,
dev_tools@internals@cli:'try'(
Write_result,
fun(_) ->
dev_tools@internals@cli:success(
<<Outfile/binary, " created"/utf8>>,
fun() -> dev_tools@internals@cli:return(nil) end
)
end
)
end
end
).
-spec install_dependencies(binary()) -> dev_tools@internals@cli:cli(nil).
install_dependencies(Root) ->
dev_tools@internals@cli:log(
<<"Installing jsdom"/utf8>>,
fun() ->
Install_dev_result = begin
_pipe = novdom_dev_tools_ffi:exec(
<<"bun"/utf8>>,
[<<"install"/utf8>>, <<"--dev"/utf8>>, <<"jsdom"/utf8>>],
Root
),
gleam@result:map_error(
_pipe,
fun(Pair) ->
{dependency_installation_error,
erlang:element(2, Pair),
<<"bun"/utf8>>}
end
)
end,
dev_tools@internals@cli:'try'(
Install_dev_result,
fun(_) ->
Install_result = begin
_pipe@1 = novdom_dev_tools_ffi:exec(
<<"bun"/utf8>>,
[<<"install"/utf8>>,
<<"quill"/utf8>>,
<<"tailwind-merge"/utf8>>],
Root
),
gleam@result:map_error(
_pipe@1,
fun(Pair@1) ->
{dependency_installation_error,
erlang:element(2, Pair@1),
<<"bun"/utf8>>}
end
)
end,
dev_tools@internals@cli:'try'(
Install_result,
fun(_) ->
dev_tools@internals@cli:success(
<<"jsdom installed"/utf8>>,
fun() -> dev_tools@internals@cli:return(nil) end
)
end
)
end
)
end
).
-spec create() -> dev_tools@internals@cli:cli(nil).
create() ->
dev_tools@internals@cli:log(
<<"Creating project structure"/utf8>>,
fun() ->
Root = dev_tools@internals@project:root(),
Outdir = filepath:join(Root, <<"build/.novdom"/utf8>>),
simplifile:create_directory_all(Outdir),
dev_tools@internals@cli:do(
create_html(
Outdir,
<<"index_dev.html"/utf8>>,
<<"<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\" />
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />
<link rel=\"stylesheet\" type=\"text/css\" href=\"./priv/static/iui.css\" />
<title>🚧 iui</title>
<!-- Uncomment this if you add the TailwindCSS integration -->
<!-- <link rel=\"stylesheet\" href=\"/priv/static/iui.css> -->
<script type=\"module\" src=\"/priv/static/iui.mjs\"></script>
</head>
<body>
<div id=\"_unrendered_\" hidden></div>
<div id=\"_app_\"></div>
<div id=\"_drag_\"></div>
</body>
<style>
html,
body,
#_app_,
#_drag_ {
height: 100%;
margin: 0;
padding: 0;
}
#_drag_ {
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
background: transparent;
pointer-events: none;
--mouse-x: 0;
--mouse-y: 0;
}
</style>
<script>
const drag = document.getElementById(\"_drag_\")
const mousemove = (e) => {
drag.style.setProperty(\"--mouse-x\", e.clientX + \"px\")
drag.style.setProperty(\"--mouse-y\", e.clientY + \"px\")
}
document.addEventListener(\"mousemove\", mousemove)
</script>
</html>
"/utf8>>
),
fun(_) ->
dev_tools@internals@cli:do(
create_html(
Outdir,
<<"index.html"/utf8>>,
<<"<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\" />
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />
<link rel=\"stylesheet\" type=\"text/css\" href=\"./priv/static/iui.css\" />
<title>🚧 iui</title>
<!-- Uncomment this if you add the TailwindCSS integration -->
<!-- <link rel=\"stylesheet\" href=\"/priv/static/iui.css> -->
<script type=\"module\" src=\"/priv/static/iui.mjs\"></script>
</head>
<body>
<div id=\"_unrendered_\" hidden></div>
<div id=\"_app_\"></div>
<div id=\"_drag_\"></div>
</body>
<style>
html,
body,
#_app_,
#_drag_ {
height: 100%;
margin: 0;
padding: 0;
}
#_drag_ {
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
background: transparent;
pointer-events: none;
--mouse-x: 0;
--mouse-y: 0;
}
</style>
<script>
const drag = document.getElementById(\"_drag_\")
const mousemove = (e) => {
drag.style.setProperty(\"--mouse-x\", e.clientX + \"px\")
drag.style.setProperty(\"--mouse-y\", e.clientY + \"px\")
}
document.addEventListener(\"mousemove\", mousemove)
</script>
</html>
"/utf8>>
),
fun(_) ->
dev_tools@internals@cli:do(
install_dependencies(Root),
fun(_) ->
dev_tools@internals@cli:return(nil)
end
)
end
)
end
)
end
).
-spec command() -> glint:command(nil).
command() ->
Description = <<"Create project structure"/utf8>>,
glint:command_help(
Description,
fun() ->
glint:unnamed_args(
{eq_args, 0},
fun() ->
glint:command(
fun(_, _, Flags) ->
case dev_tools@internals@cli:run(create(), Flags) of
{ok, _} ->
nil;
{error, Error} ->
dev_tools@internals@error:explain(Error)
end
end
)
end
)
end
).