Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --depends-on Flag To Umbrella Web Generator #5691

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions installer/lib/mix/tasks/phx.new.ex
Expand Up @@ -134,6 +134,7 @@ defmodule Mix.Tasks.Phx.New do
html: :boolean,
gettext: :boolean,
umbrella: :boolean,
depends_on: :string,
verbose: :boolean,
live: :boolean,
dashboard: :boolean,
Expand Down
4 changes: 3 additions & 1 deletion installer/lib/phx_new/generator.ex
Expand Up @@ -186,7 +186,7 @@ defmodule Phx.New.Generator do
# means creating a database like FoO is the same as foo in
# some storages.
{adapter_app, adapter_module, adapter_config} =
get_ecto_adapter(db, String.downcase(project.app), project.app_mod)
get_ecto_adapter(db, String.downcase(project.app), project.depends_on_mod)

{web_adapter_app, web_adapter_vsn, web_adapter_module} = get_web_adapter(web_adapter)

Expand Down Expand Up @@ -219,6 +219,8 @@ defmodule Phx.New.Generator do
signing_salt: random_string(8),
lv_signing_salt: random_string(8),
in_umbrella: project.in_umbrella?,
depends_on_app: project.depends_on_app,
depends_on_mod: inspect(project.depends_on_mod) || inspect(project.app_mod),
asset_builders: Enum.filter([tailwind && :tailwind, esbuild && :esbuild], & &1),
javascript: esbuild,
css: tailwind,
Expand Down
2 changes: 2 additions & 0 deletions installer/lib/phx_new/project.ex
Expand Up @@ -15,6 +15,8 @@ defmodule Phx.New.Project do
web_path: nil,
opts: :unset,
in_umbrella?: false,
depends_on_app: nil,
depends_on_mod: nil,
binding: [],
generators: [timestamp_type: :utc_datetime]

Expand Down
2 changes: 2 additions & 0 deletions installer/lib/phx_new/single.ex
Expand Up @@ -125,6 +125,8 @@ defmodule Phx.New.Single do
%Project{
project
| web_app: app,
depends_on_app: app,
depends_on_mod: project.root_mod,
lib_web_name: "#{app}_web",
web_namespace: Module.concat(["#{project.root_mod}Web"]),
web_path: project.base_path
Expand Down
2 changes: 2 additions & 0 deletions installer/lib/phx_new/umbrella.ex
Expand Up @@ -40,6 +40,8 @@ defmodule Phx.New.Umbrella do
| web_app: web_app,
lib_web_name: web_app,
web_namespace: web_namespace,
depends_on_app: app,
depends_on_mod: project.app_mod,
generators: [context_app: :"#{app}"],
web_path: Path.join(project.project_path, "apps/#{web_app}/")
}
Expand Down
8 changes: 6 additions & 2 deletions installer/lib/phx_new/web.ex
Expand Up @@ -56,17 +56,21 @@ defmodule Phx.New.Web do
"phx_web/components/layouts/app.html.heex": "lib/:web_app/components/layouts/app.html.heex"}
])

def prepare_project(%Project{app: app} = project) when not is_nil(app) do
def prepare_project(%Project{app: app, opts: opts} = project) when not is_nil(app) do
web_path = Path.expand(project.base_path)
project_path = Path.dirname(Path.dirname(web_path))
depends_on = Keyword.get(opts, :depends_on, false)

%Project{
project
| in_umbrella?: true,
project_path: project_path,
web_path: web_path,
web_app: app,
generators: [context_app: false],
depends_on_app: depends_on || app,
depends_on_mod:
(depends_on && Module.concat([Macro.camelize(depends_on)])) || project.app_mod,
generators: [context_app: :"#{depends_on}"],
web_namespace: project.app_mod
}
end
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/phx_test/support/conn_case.ex
Expand Up @@ -32,7 +32,7 @@ defmodule <%= @web_namespace %>.ConnCase do
end<%= if @ecto do %>

setup tags do
<%= @app_module %>.DataCase.setup_sandbox(tags)
<%= @depends_on_mod %>.DataCase.setup_sandbox(tags)
{:ok, conn: Phoenix.ConnTest.build_conn()}
end<% else %>

Expand Down
Expand Up @@ -3,7 +3,7 @@ import Config
<%= if @namespaced? || @ecto || @generators do %>
config :<%= @web_app_name %><%= if @namespaced? do %>,
namespace: <%= @web_namespace %><% end %><%= if @ecto do %>,
ecto_repos: [<%= @app_module %>.Repo]<% end %><%= if @generators do %>,
ecto_repos: [<%= @depends_on_mod %>.Repo]<% end %><%= if @generators do %>,
generators: <%= inspect @generators %><% end %>

<% end %># Configures the endpoint
Expand All @@ -14,7 +14,7 @@ config :<%= @web_app_name %>, <%= @endpoint_module %>,
formats: [<%= if @html do%>html: <%= @web_namespace %>.ErrorHTML, <% end %>json: <%= @web_namespace %>.ErrorJSON],
layout: false
],
pubsub_server: <%= @app_module %>.PubSub,
pubsub_server: <%= @depends_on_mod %>.PubSub,
live_view: [signing_salt: "<%= @lv_signing_salt %>"]<%= if @javascript do %>

# Configure esbuild (the version is required)
Expand Down
Expand Up @@ -69,7 +69,7 @@ config :<%= @web_app_name %>, <%= @endpoint_module %>,
# Also, you may need to configure the Swoosh API client of your choice if you
# are not using SMTP. Here is an example of the configuration:
#
# config :<%= @app_name %>, <%= @app_module %>.Mailer,
# config :<%= @app_name %>, <%= @depends_on_mod %>.Mailer,
# adapter: Swoosh.Adapters.Mailgun,
# api_key: System.get_env("MAILGUN_API_KEY"),
# domain: System.get_env("MAILGUN_DOMAIN")
Expand Down
4 changes: 2 additions & 2 deletions installer/templates/phx_umbrella/apps/app_name_web/mix.exs
Expand Up @@ -54,8 +54,8 @@ defmodule <%= @web_namespace %>.MixProject do
depth: 1},<% end %>
{:telemetry_metrics, "~> 0.6"},
{:telemetry_poller, "~> 1.0"},<%= if @gettext do %>
{:gettext, "~> 0.20"},<% end %><%= if @app_name != @web_app_name do %>
{:<%= @app_name %>, in_umbrella: true},<% end %>
{:gettext, "~> 0.20"},<% end %><%= if @in_umbrella do %>
{:<%= @depends_on_app %>, in_umbrella: true},<% end %>
{:jason, "~> 1.2"},
{<%= inspect @web_adapter_app %>, "<%= @web_adapter_vsn %>"}
]
Expand Down
10 changes: 5 additions & 5 deletions installer/templates/phx_web/telemetry.ex
Expand Up @@ -52,23 +52,23 @@ defmodule <%= @web_namespace %>.Telemetry do
),<%= if @ecto do %>

# Database Metrics
summary("<%= @app_name %>.repo.query.total_time",
summary("<%= @depends_on_app %>.repo.query.total_time",
unit: {:native, :millisecond},
description: "The sum of the other measurements"
),
summary("<%= @app_name %>.repo.query.decode_time",
summary("<%= @depends_on_app %>.repo.query.decode_time",
unit: {:native, :millisecond},
description: "The time spent decoding the data received from the database"
),
summary("<%= @app_name %>.repo.query.query_time",
summary("<%= @depends_on_app %>.repo.query.query_time",
unit: {:native, :millisecond},
description: "The time spent executing the query"
),
summary("<%= @app_name %>.repo.query.queue_time",
summary("<%= @depends_on_app %>.repo.query.queue_time",
unit: {:native, :millisecond},
description: "The time spent waiting for a database connection"
),
summary("<%= @app_name %>.repo.query.idle_time",
summary("<%= @depends_on_app %>.repo.query.idle_time",
unit: {:native, :millisecond},
description:
"The time the connection spent waiting before being checked out for the query"
Expand Down