Skip to content

Commit

Permalink
Update more tasks for umbrella
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed May 1, 2024
1 parent 5e53b25 commit 3aaa87a
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 41 deletions.
6 changes: 6 additions & 0 deletions lib/mix/tasks/lvn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ defmodule Mix.Tasks.Lvn do
@impl true
@doc false
def run([version]) when version in ~w(-v --version) do
if Mix.Project.umbrella?() do
Mix.raise(
"mix lvn must be invoked from within your *_web application root directory"
)
end

Mix.shell().info("LiveView Native v#{@version}")
end

Expand Down
1 change: 1 addition & 0 deletions lib/mix/tasks/lvn.gen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule Mix.Tasks.Lvn.Gen do
"mix lvn.gen must be invoked from within your *_web application root directory"
)
end

context = Context.build(args, __MODULE__)

if Keyword.get(context.opts, :copy, true) do
Expand Down
6 changes: 6 additions & 0 deletions lib/mix/tasks/lvn.gen.layout.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ defmodule Mix.Tasks.Lvn.Gen.Layout do
@impl true
@doc false
def run(args) do
if Mix.Project.umbrella?() do
Mix.raise(
"mix lvn.gen.layout must be invoked from within your *_web application root directory"
)
end

context = Context.build(args, __MODULE__)

files = files_to_be_generated(context)
Expand Down
5 changes: 5 additions & 0 deletions lib/mix/tasks/lvn.gen.live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ defmodule Mix.Tasks.Lvn.Gen.Live do
@impl true
@doc false
def run(args) do
if Mix.Project.umbrella?() do
Mix.raise(
"mix lvn.gen.live must be invoked from within your *_web application root directory"
)
end
context = Context.build(args, __MODULE__)

files = files_to_be_generated(context)
Expand Down
6 changes: 6 additions & 0 deletions lib/mix/tasks/lvn.setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ defmodule Mix.Tasks.Lvn.Setup do
@impl true
@doc false
def run(args) do
if Mix.Project.umbrella?() do
Mix.raise(
"mix lvn.setup must be invoked from within your *_web application root directory"
)
end

context = Context.build(args, __MODULE__)

plugins =
Expand Down
64 changes: 48 additions & 16 deletions test/mix/tasks/lvn.gen.layout_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,59 @@ defmodule Mix.Tasks.Lvn.Gen.LayoutTest do
:ok
end

test "generates layout file and the layout templates into the proper format directory", config do
in_tmp_live_project config.test, fn ->
Gen.Layout.run(["gameboy"])
assert_file "lib/live_view_native_web/components/layouts_gameboy/app.gameboy.neex"
assert_file "lib/live_view_native_web/components/layouts_gameboy/root.gameboy.neex", fn file ->
assert file =~ "app.gameboy"
describe "when a single app" do
test "generates layout file and the layout templates into the proper format directory", config do
in_tmp_live_project config.test, fn ->
Gen.Layout.run(["gameboy"])
assert_file "lib/live_view_native_web/components/layouts_gameboy/app.gameboy.neex"
assert_file "lib/live_view_native_web/components/layouts_gameboy/root.gameboy.neex", fn file ->
assert file =~ "app.gameboy"
end
assert_file "lib/live_view_native_web/components/layouts.gameboy.ex", fn file ->
assert file =~ "LiveViewNativeNative"
end
end
assert_file "lib/live_view_native_web/components/layouts.gameboy.ex", fn file ->
assert file =~ "LiveViewNativeNative"
end

test "will raise with message if invalid format is given", config do
in_tmp_live_project config.test, fn ->
assert_raise(Mix.Error, fn() ->
Gen.Layout.run(["other"])
end)
refute_file "lib/live_view_native_web/components/layouts_gameboy/app.other.neex"
refute_file "lib/live_view_native_web/components/layouts_gameboy/root.other.neex"
refute_file "lib/live_view_native_web/components/layouts.other.ex"
end
end
end

test "will raise with message if invalid format is given", config do
in_tmp_live_project config.test, fn ->
assert_raise(Mix.Error, fn() ->
Gen.Layout.run(["other"])
end)
refute_file "lib/live_view_native_web/components/layouts_gameboy/app.other.neex"
refute_file "lib/live_view_native_web/components/layouts_gameboy/root.other.neex"
refute_file "lib/live_view_native_web/components/layouts.other.ex"
describe "when an umbrella app" do
test "generates layout file and the layout templates into the proper format directory", config do
in_tmp_live_umbrella_project config.test, fn ->
File.cd!("live_view_native_web", fn ->
Gen.Layout.run(["gameboy"])
assert_file "lib/live_view_native_web/components/layouts_gameboy/app.gameboy.neex"
assert_file "lib/live_view_native_web/components/layouts_gameboy/root.gameboy.neex", fn file ->
assert file =~ "app.gameboy"
end
assert_file "lib/live_view_native_web/components/layouts.gameboy.ex", fn file ->
assert file =~ "LiveViewNativeNative"
end
end)
end
end

test "will raise with message if invalid format is given", config do
in_tmp_live_umbrella_project config.test, fn ->
File.cd!("live_view_native_web", fn ->
assert_raise(Mix.Error, fn() ->
Gen.Layout.run(["other"])
end)
refute_file "lib/live_view_native_web/components/layouts_gameboy/app.other.neex"
refute_file "lib/live_view_native_web/components/layouts_gameboy/root.other.neex"
refute_file "lib/live_view_native_web/components/layouts.other.ex"
end)
end
end
end
end
57 changes: 43 additions & 14 deletions test/mix/tasks/lvn.gen.live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,53 @@ defmodule Mix.Tasks.Lvn.Gen.LiveTest do
:ok
end

test "generates a live file and the templates into the proper format directory", config do
in_tmp_live_project config.test, fn ->
Gen.Live.run(["gameboy", "Home"])
assert_file "lib/live_view_native_web/live/gameboy/home_live.gameboy.neex"
assert_file "lib/live_view_native_web/live/home_live.gameboy.ex", fn file ->
assert file =~ "HomeLive.GameBoy"
assert file =~ "use LiveViewNativeNative, [:render_component, format: :gameboy]"
describe "when a single app" do
test "generates a live file and the templates into the proper format directory", config do
in_tmp_live_project config.test, fn ->
Gen.Live.run(["gameboy", "Home"])
assert_file "lib/live_view_native_web/live/gameboy/home_live.gameboy.neex"
assert_file "lib/live_view_native_web/live/home_live.gameboy.ex", fn file ->
assert file =~ "HomeLive.GameBoy"
assert file =~ "use LiveViewNativeNative, [:render_component, format: :gameboy]"
end
end
end

test "will raise with message if invalid format is given", config do
in_tmp_live_project config.test, fn ->
assert_raise(Mix.Error, fn() ->
Gen.Live.run(["other"])
end)
refute_file "lib/live_view_native_web/live/gameboy/home_live.gameboy.neex"
refute_file "lib/live_view_native_web/live/home_live.gameboy.ex"
end
end
end

test "will raise with message if invalid format is given", config do
in_tmp_live_project config.test, fn ->
assert_raise(Mix.Error, fn() ->
Gen.Live.run(["other"])
end)
refute_file "lib/live_view_native_web/live/gameboy/home_live.gameboy.neex"
refute_file "lib/live_view_native_web/live/home_live.gameboy.ex"
describe "when an umbrella app" do
test "generates a live file and the templates into the proper format directory", config do
in_tmp_live_umbrella_project config.test, fn ->
File.cd!("live_view_native_web", fn ->
Gen.Live.run(["gameboy", "Home"])
assert_file "lib/live_view_native_web/live/gameboy/home_live.gameboy.neex"
assert_file "lib/live_view_native_web/live/home_live.gameboy.ex", fn file ->
assert file =~ "HomeLive.GameBoy"
assert file =~ "use LiveViewNativeNative, [:render_component, format: :gameboy]"
end
end)
end
end

test "will raise with message if invalid format is given", config do
in_tmp_live_umbrella_project config.test, fn ->
File.cd!("live_view_native_web", fn ->
assert_raise(Mix.Error, fn() ->
Gen.Live.run(["other"])
end)
refute_file "lib/live_view_native_web/live/gameboy/home_live.gameboy.neex"
refute_file "lib/live_view_native_web/live/home_live.gameboy.ex"
end)
end
end
end
end
24 changes: 13 additions & 11 deletions test/mix/tasks/lvn.gen_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Mix.Tasks.Lvn.GenTest do
:ok
end

describe "when not an umbrella" do
describe "when a single app" do
test "generates the `Native` module into the project's lib directory", config do
in_tmp_live_project config.test, fn ->
Gen.run([])
Expand All @@ -30,24 +30,26 @@ defmodule Mix.Tasks.Lvn.GenTest do
end
end

describe "when an umbrella" do
describe "when an umbrella app" do
test "generates the `Native` module into the project's lib directory", config do
in_tmp_live_umbrella_project config.test, fn ->
File.cd!("live_view_native_web")
Gen.run([])
assert_file "lib/live_view_native_native.ex", fn file ->
assert file =~ "LiveViewNativeNative"
end
File.cd!("live_view_native_web", fn ->
Gen.run([])
assert_file "lib/live_view_native_native.ex", fn file ->
assert file =~ "LiveViewNativeNative"
end
end)
end
end

test "will raise with message if any arguments are given", config do
in_tmp_live_umbrella_project config.test, fn ->
File.cd!("live_view_native_web")
assert_raise(Mix.Error, fn() ->
Gen.run(["gameboy"])
File.cd!("live_view_native_web", fn ->
assert_raise(Mix.Error, fn() ->
Gen.run(["gameboy"])
end)
refute_file "lib/live_view_native_native.ex"
end)
refute_file "lib/live_view_native_native.ex"
end
end
end
Expand Down

0 comments on commit 3aaa87a

Please sign in to comment.