Skip to content

Commit

Permalink
Raise on missing deps for lvn.setup
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Dec 18, 2024
1 parent d9e0c92 commit 2a1fb09
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
31 changes: 31 additions & 0 deletions lib/mix/live_view_native.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
defmodule Mix.LiveViewNative do

import Mix.LiveViewNative.Context, only: [
compile_string: 1
]

def plugins() do
config_plugins = LiveViewNative.plugins()

Expand All @@ -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
30 changes: 3 additions & 27 deletions lib/mix/tasks/lvn.setup.ex
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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:
Expand All @@ -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

0 comments on commit 2a1fb09

Please sign in to comment.