Current section
Files
Jump to
Current section
Files
src/drip.erl
-module(drip).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/drip.gleam").
-export([main/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" `drip` vendors Lustre UI elements (Gleam, CSS, and sometimes a little FFI)\n"
" straight into your project's `src/`. Run it from the root of a Gleam +\n"
" Lustre project with `gleam run -m drip -- <command>`.\n"
"\n"
" ## Commands\n"
"\n"
" | Command | What it does |\n"
" |---------|--------------|\n"
" | `init` | Scaffolds `theme.css`, the generated `index.css`, and wires up your entry stylesheet. |\n"
" | `list` | Lists the elements in the registry, marking which are already vendored. |\n"
" | `add <element>...` | Vendors one or more elements and their dependencies into `src/<prefix>/`. |\n"
" | `remove <element>...` | Deletes the named elements' files. |\n"
"\n"
" ## Flags\n"
"\n"
" | Flag | Commands | Description |\n"
" |------|----------|-------------|\n"
" | `--prefix <dir>` | `init` | Directory under `src/` that elements vendor into, saved to `[tools.drip]` in your `gleam.toml` (default: `ui`). |\n"
" | `--source <url-or-path>` | `init` | Registry to vendor from, a URL or local path, saved to `[tools.drip]` in your `gleam.toml` (default: the latest GitHub release). |\n"
" | `--force` | `init`, `add` | Overwrite files that already exist on disk. |\n"
"\n"
" Pass `--help` to any command to see its usage. The full element catalog,\n"
" configuration reference, and live examples live at <https://drip.pink>.\n"
).
-file("src/drip.gleam", 73).
-spec colorize_line(binary()) -> binary().
colorize_line(Line) ->
case gleam@string:trim_start(Line) of
<<"+ "/utf8, _/binary>> ->
gleam_community@ansi:green(Line);
<<"- "/utf8, _/binary>> ->
gleam_community@ansi:red(Line);
<<"~ "/utf8, _/binary>> ->
gleam_community@ansi:yellow(Line);
<<"= "/utf8, _/binary>> ->
gleam_community@ansi:dim(Line);
<<"✓ "/utf8, _/binary>> ->
gleam_community@ansi:green(Line);
<<"Next steps:"/utf8, _/binary>> ->
gleam_community@ansi:bold(Line);
<<"call "/utf8, _/binary>> ->
gleam_community@ansi:bright_yellow(Line);
<<"gleam "/utf8, _/binary>> ->
gleam_community@ansi:bright_yellow(Line);
_ ->
Line
end.
-file("src/drip.gleam", 66).
-spec colorize(binary()) -> binary().
colorize(Text) ->
_pipe = Text,
_pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>),
_pipe@2 = gleam@list:map(_pipe@1, fun colorize_line/1),
gleam@string:join(_pipe@2, <<"\n"/utf8>>).
-file("src/drip.gleam", 38).
?DOC(" Entry point for the `drip` CLI, invoked by `gleam run -m drip`.\n").
-spec main() -> nil.
main() ->
Result = begin
gleam@result:'try'(
drip@internal@project:load(),
fun(Project) ->
gleam@result:map(
drip@internal@cli:run(
Project,
erlang:element(4, argv:load())
),
fun(Output) -> case Output of
<<""/utf8>> ->
nil;
_ ->
gleam_stdlib:println(colorize(Output))
end end
)
end
)
end,
case Result of
{ok, _} ->
nil;
{error, {invalid_usage, Message}} ->
gleam_stdlib:println_error(Message),
erlang:halt(1);
{error, Cause} ->
gleam_stdlib:println_error(
gleam_community@ansi:red(drip@internal@error:describe(Cause))
),
erlang:halt(1)
end.