From 2a1fb09cbacbd2c04cd60973a05ca7eed848b5f8 Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Wed, 18 Dec 2024 16:47:43 -0500 Subject: [PATCH] Raise on missing deps for lvn.setup --- lib/mix/live_view_native.ex | 31 +++++++++++++++++++++++++++++++ lib/mix/tasks/lvn.setup.ex | 30 +++--------------------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/mix/live_view_native.ex b/lib/mix/live_view_native.ex index fecee6f..548c7e4 100644 --- a/lib/mix/live_view_native.ex +++ b/lib/mix/live_view_native.ex @@ -1,4 +1,9 @@ defmodule Mix.LiveViewNative do + + import Mix.LiveViewNative.Context, only: [ + compile_string: 1 + ] + def plugins() do config_plugins = LiveViewNative.plugins() @@ -22,4 +27,30 @@ defmodule Mix.LiveViewNative do Map.merge(found_plugins, config_plugins) end + + def detect_necessary_deps() do + deps = [ + :live_view_native_stylesheet, + :live_view_native_live_form + ] + + installed_deps = Mix.Project.deps_tree() |> Map.keys() + + deps + |> Enum.reject(fn(dep) -> dep in installed_deps end) + |> case do + [] -> :noop + deps -> + msg = """ + <%= IO.ANSI.red() %><%= IO.ANSI.bright() %>The following dependencies are missing from your application:<%= IO.ANSI.reset() %> + <%= for dep <- deps do %> + * <%= dep %><% end %> + + These are necessary for LiveView Native that you must install before continuing. + """ + |> compile_string() + + raise msg + end + end end diff --git a/lib/mix/tasks/lvn.setup.ex b/lib/mix/tasks/lvn.setup.ex index 4e4b498..d9a16a3 100644 --- a/lib/mix/tasks/lvn.setup.ex +++ b/lib/mix/tasks/lvn.setup.ex @@ -1,8 +1,8 @@ defmodule Mix.Tasks.Lvn.Setup do use Mix.Task - import Mix.LiveViewNative.Context, only: [ - compile_string: 1 + import Mix.LiveViewNative, only: [ + detect_necessary_deps: 0 ] @shortdoc "Prints LiveView Native Setup information" @@ -22,20 +22,7 @@ defmodule Mix.Tasks.Lvn.Setup do ) end - detect_recommended_deps() - |> case do - [] -> :noop - deps -> - """ - <%= IO.ANSI.red() %><%= IO.ANSI.bright() %>The following dependencies are missing from your application:<%= IO.ANSI.reset() %> - <%= for dep <- deps do %> - * <%= dep %><% end %> - - While not necessary it is highly recommended that you install them before continuing. - """ - |> compile_string() - |> Mix.shell.info() - end + detect_necessary_deps() """ To setup your application with LiveView Native run: @@ -45,15 +32,4 @@ defmodule Mix.Tasks.Lvn.Setup do """ |> Mix.shell().info() end - - defp detect_recommended_deps() do - deps = [ - :live_view_native_stylesheet, - :live_view_native_live_form - ] - - installed_deps = Mix.Project.deps_tree() |> Map.keys() - - Enum.reject(deps, fn(dep) -> dep in installed_deps end) - end end