diff --git a/installer/lib/mix/tasks/phx.new.ex b/installer/lib/mix/tasks/phx.new.ex index 95726b3780..c0e6cf4524 100644 --- a/installer/lib/mix/tasks/phx.new.ex +++ b/installer/lib/mix/tasks/phx.new.ex @@ -140,7 +140,8 @@ defmodule Mix.Tasks.Phx.New do install: :boolean, prefix: :string, mailer: :boolean, - adapter: :string + adapter: :string, + from_elixir_install: :boolean, ] @impl true diff --git a/installer/lib/phx_new/generator.ex b/installer/lib/phx_new/generator.ex index b0c0a9f0d1..2df0d683fb 100644 --- a/installer/lib/phx_new/generator.ex +++ b/installer/lib/phx_new/generator.ex @@ -178,6 +178,7 @@ defmodule Phx.New.Generator do tailwind = Keyword.get(opts, :tailwind, assets) mailer = Keyword.get(opts, :mailer, true) dev = Keyword.get(opts, :dev, false) + from_elixir_install = Keyword.get(opts, :from_elixir_install, false) phoenix_path = phoenix_path(project, dev, false) phoenix_path_umbrella_root = phoenix_path(project, dev, true) @@ -188,7 +189,8 @@ defmodule Phx.New.Generator do {adapter_app, adapter_module, adapter_config} = get_ecto_adapter(db, String.downcase(project.app), project.app_mod) - {web_adapter_app, web_adapter_vsn, web_adapter_module, web_adapter_docs} = get_web_adapter(web_adapter) + {web_adapter_app, web_adapter_vsn, web_adapter_module, web_adapter_docs} = + get_web_adapter(web_adapter) pubsub_server = get_pubsub_server(project.app_mod) @@ -238,12 +240,33 @@ defmodule Phx.New.Generator do web_adapter_docs: web_adapter_docs, generators: nil_if_empty(project.generators ++ adapter_generators(adapter_config)), namespaced?: namespaced?(project), - dev: dev + dev: dev, + from_elixir_install: from_elixir_install, + elixir_install_otp_bin_path: from_elixir_install && elixir_install_otp_bin_path(), + elixir_install_bin_path: from_elixir_install && elixir_install_bin_path() ] %Project{project | binding: binding} end + def elixir_install_otp_bin_path do + "erl" + |> System.find_executable() + |> Path.split() + |> Enum.drop(-1) + |> Path.join() + |> Path.relative_to(System.user_home()) + end + + def elixir_install_bin_path do + "elixir" + |> System.find_executable() + |> Path.split() + |> Enum.drop(-1) + |> Path.join() + |> Path.relative_to(System.user_home()) + end + defp namespaced?(project) do Macro.camelize(project.app) != inspect(project.app_mod) end @@ -304,8 +327,16 @@ defmodule Phx.New.Generator do Mix.raise("Unknown database #{inspect(db)}") end - defp get_web_adapter("cowboy"), do: {:plug_cowboy, "~> 2.7", Phoenix.Endpoint.Cowboy2Adapter, "https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html"} - defp get_web_adapter("bandit"), do: {:bandit, "~> 1.5", Bandit.PhoenixAdapter, "https://hexdocs.pm/bandit/Bandit.html#t:options/0"} + defp get_web_adapter("cowboy"), + do: + {:plug_cowboy, "~> 2.7", Phoenix.Endpoint.Cowboy2Adapter, + "https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html"} + + defp get_web_adapter("bandit"), + do: + {:bandit, "~> 1.5", Bandit.PhoenixAdapter, + "https://hexdocs.pm/bandit/Bandit.html#t:options/0"} + defp get_web_adapter(other), do: Mix.raise("Unknown web adapter #{inspect(other)}") defp fs_db_config(app, module) do diff --git a/installer/templates/phx_web/controllers/page_html/home.html.heex b/installer/templates/phx_web/controllers/page_html/home.html.heex index fe4507e466..dc71bbaec1 100644 --- a/installer/templates/phx_web/controllers/page_html/home.html.heex +++ b/installer/templates/phx_web/controllers/page_html/home.html.heex @@ -37,7 +37,76 @@ fill="#A41C42" fill-opacity=".2" /> - + <%= if @from_elixir_install do %> +
+
+
+ + + + + +

+ Finish your Elixir setup! +

+

<%= if match?({:win32, _}, :os.type()) do %> + Elixir has been installed to + + %USERPROFILE%\.elixir-install + + and activated in your current shell.
+
Add to your + %PROFILE + or similar to ensure it is always activated:<% else %> + Elixir has been installed to + ~/.elixir-install + and activated in your current shell.
+
Add to your + ~/.bashrc + or similar to ensure it is always activated:<% end %> +

+
+ + <%= if match?({:win32, _}, :os.type()) do %># If you are using powershell, add: + +$env:PATH = "$env:USERPROFILE\<%= @elixir_install_otp_bin_path %>;$env:PATH" +$env:PATH = "$env:USERPROFILE\<%= @elixir_install_bin_path %>;$env:PATH" + +# If you are using cmd, add: + +set PATH=%%USERPROFILE%%\<%= @elixir_install_otp_bin_path %>;%%PATH%% +set PATH=%%USERPROFILE%%\<%= @elixir_install_bin_path %>;%%PATH%%<% else %>export PATH=$HOME/<%= @elixir_install_otp_bin_path %>:$PATH +export PATH=$HOME/<%= @elixir_install_bin_path %>:$PATH<% end %> +
+
+
+
<% end %>