Skip to content

Commit

Permalink
Use proper project and base path references, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Sep 12, 2023
1 parent 6f2b3da commit 249aa01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 5 additions & 2 deletions installer/lib/mix/tasks/phx.new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ defmodule Mix.Tasks.Phx.New do
Mix.Tasks.Help.run(["phx.new"])

{opts, [base_path | _]} ->
generator = if opts[:umbrella], do: Umbrella, else: Single
generate(base_path, generator, :project_path, opts)
if opts[:umbrella] do
generate(base_path, Umbrella, :project_path, opts)
else
generate(base_path, Single, :base_path, opts)
end
end
end

Expand Down
16 changes: 10 additions & 6 deletions installer/lib/phx_new/single.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Phx.New.Single do
"phx_single/config/prod.exs": "config/prod.exs",
"phx_single/config/runtime.exs": "config/runtime.exs",
"phx_single/config/test.exs": "config/test.exs"},
{:eex, :project,
{:eex, :web,
"phx_single/lib/app_name/application.ex": "lib/:app/application.ex",
"phx_single/lib/app_name.ex": "lib/:app.ex",
"phx_web/controllers/error_json.ex": "lib/:lib_web_name/controllers/error_json.ex",
Expand All @@ -26,7 +26,7 @@ defmodule Phx.New.Single do
"phx_single/test/test_helper.exs": "test/test_helper.exs",
"phx_test/controllers/error_json_test.exs":
"test/:lib_web_name/controllers/error_json_test.exs"},
{:keep, :project,
{:keep, :web,
"phx_web/controllers": "lib/:lib_web_name/controllers",
"phx_test/controllers": "test/:lib_web_name/controllers"}
])
Expand Down Expand Up @@ -102,15 +102,19 @@ defmodule Phx.New.Single do
{:eex, :app, "phx_mailer/lib/app_name/mailer.ex": "lib/:app/mailer.ex"}
])

def prepare_project(%Project{app: app} = project) when not is_nil(app) do
%Project{project | project_path: project.base_path}
def prepare_project(%Project{app: app, base_path: base_path} = project) when not is_nil(app) do
if in_umbrella?(base_path) do
%Project{project | in_umbrella?: true, project_path: Path.dirname(Path.dirname(base_path))}
else
%Project{project | in_umbrella?: false, project_path: base_path}
end
|> put_app()
|> put_root_app()
|> put_web_app()
end

defp put_app(%Project{base_path: base_path} = project) do
%Project{project | in_umbrella?: in_umbrella?(base_path), app_path: base_path}
%Project{project | app_path: base_path}
end

defp put_root_app(%Project{app: app, opts: opts} = project) do
Expand All @@ -127,7 +131,7 @@ defmodule Phx.New.Single do
| web_app: app,
lib_web_name: "#{app}_web",
web_namespace: Module.concat(["#{project.root_mod}Web"]),
web_path: project.project_path
web_path: project.base_path
}
end

Expand Down
4 changes: 4 additions & 0 deletions installer/test/phx_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ defmodule Mix.Tasks.Phx.NewTest do
assert file =~ "deps_path: \"../../deps\""
assert file =~ "lockfile: \"../../mix.lock\""
end)

refute_file("phx_blog/config/config.exs")
end)

assert_file("config/config.exs", "PhxBlogWeb.Endpoint")
end)
end

Expand Down

0 comments on commit 249aa01

Please sign in to comment.