-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( <>, 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( <>, 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>>, <<" 🚧 iui
"/utf8>> ), fun(_) -> dev_tools@internals@cli:do( create_html( Outdir, <<"index.html"/utf8>>, <<" 🚧 iui
"/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 ).