diff --git a/installer/lib/mix/tasks/phx.new.ex b/installer/lib/mix/tasks/phx.new.ex index b37d02a4fc..e880431e1e 100644 --- a/installer/lib/mix/tasks/phx.new.ex +++ b/installer/lib/mix/tasks/phx.new.ex @@ -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 diff --git a/installer/lib/phx_new/single.ex b/installer/lib/phx_new/single.ex index cab25854a1..9c6cffc67c 100644 --- a/installer/lib/phx_new/single.ex +++ b/installer/lib/phx_new/single.ex @@ -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", @@ -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"} ]) @@ -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 @@ -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 diff --git a/installer/test/phx_new_test.exs b/installer/test/phx_new_test.exs index be2e4db816..75d8744d1b 100644 --- a/installer/test/phx_new_test.exs +++ b/installer/test/phx_new_test.exs @@ -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