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

phx.gen.live doesn't work in umbrella app #4566

Closed
cjbottaro opened this issue Oct 27, 2021 · 3 comments
Closed

phx.gen.live doesn't work in umbrella app #4566

cjbottaro opened this issue Oct 27, 2021 · 3 comments

Comments

@cjbottaro
Copy link
Contributor

cjbottaro commented Oct 27, 2021

$ mix phx.gen.live Signup
** (Mix) mix phx.gen.live must be invoked from within your *_web application root directory

$ cd apps/web

$ mix phx.gen.live --no-context --no-schema Signup
** (Mix) Invalid arguments

mix phx.gen.html, phx.gen.json, phx.gen.live, and phx.gen.context
expect a context module name, followed by singular and plural names
of the generated resource, ending with any number of attributes.
For example:

    mix phx.gen.html Accounts User users name:string
    mix phx.gen.json Accounts User users name:string
    mix phx.gen.live Accounts User users name:string
    mix phx.gen.context Accounts User users name:string

The context serves as the API boundary for the given resource.
Multiple resources may belong to a context and a resource may be
split over distinct contexts (such as Accounts.User and Payments.User).

$ mix phx.gen.live --no-context --no-schema Foo Signup users
** (Mix) no context_app configured for current application web.

Add the context_app generators config in config.exs, or pass the
--context-app option explicitly to the generators. For example:

via config:

    config :web, :generators,
      context_app: :some_app

via cli option:

    mix phx.gen.[task] --context-app some_app

Note: cli option only works when `context_app` is not set to `false`
in the config.

# add to my config/config.exs: config :web, :generators, context_app: :web

$ mix phx.gen.live --no-context --no-schema --context-app web Foo Signup users
* creating lib/web_web/live/signup_live/show.ex
* creating lib/web_web/live/signup_live/index.ex
* creating lib/web_web/live/signup_live/form_component.ex
* creating lib/web_web/live/signup_live/form_component.html.heex
* creating lib/web_web/live/signup_live/index.html.heex
* creating lib/web_web/live/signup_live/show.html.heex
* creating test/web_web/live/signup_live_test.exs
* creating lib/web_web/live/modal_component.ex
* creating lib/web_web/live/live_helpers.ex
** (File.Error) could not read file "lib/web_web.ex": no such file or directory
    (elixir 1.12.3) lib/file.ex:355: File.read!/1
    lib/mix/tasks/phx.gen.live.ex:151: Mix.Tasks.Phx.Gen.Live.maybe_inject_helpers/1
    lib/mix/tasks/phx.gen.live.ex:103: Mix.Tasks.Phx.Gen.Live.run/1
    (mix 1.12.3) lib/mix/task.ex:394: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.12.3) lib/mix/cli.ex:84: Mix.CLI.run_task/2

It finally generates some things, but crashes before it finishes. Further, it seems to completely ignore --no-context and --no-schema.

I'm using Phoenix 1.6.2.

Thanks for the help.

@cjbottaro
Copy link
Contributor Author

Also, more or less the same thing happens with phx.gen.auth.

@milmazz
Copy link
Contributor

milmazz commented Nov 18, 2021

@cjbottaro I couldn't replicate your scenario, please see the details:

$ mix archive.uninstall phx_new
Are you sure you want to uninstall /Users/milmazz/.asdf/installs/elixir/1.12.2-otp-24/.mix/archives/phx_new-1.6.0? [Yn] Y
$ mix archive.install hex phx_new
Resolving Hex dependencies...
Dependency resolution completed:
New:
  phx_new 1.6.2
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 11 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.6.2.ez" with MIX_ENV=prod
Are you sure you want to install "phx_new-1.6.2.ez"? [Yn] Y
* creating /Users/milmazz/.asdf/installs/elixir/1.12.2-otp-24/.mix/archives/phx_new-1.6.2
Create Umbrella Project

$ mix phx.new web --umbrella
* creating web_umbrella/.gitignore
* creating web_umbrella/config/config.exs
* creating web_umbrella/config/dev.exs
* creating web_umbrella/config/test.exs
* creating web_umbrella/config/prod.exs
* creating web_umbrella/config/runtime.exs
* creating web_umbrella/mix.exs
* creating web_umbrella/README.md
* creating web_umbrella/.formatter.exs
* creating web_umbrella/apps/web_web/lib/web_web.ex
* creating web_umbrella/apps/web_web/lib/web_web/application.ex
* creating web_umbrella/apps/web_web/lib/web_web/endpoint.ex
* creating web_umbrella/apps/web_web/lib/web_web/router.ex
* creating web_umbrella/apps/web_web/lib/web_web/telemetry.ex
* creating web_umbrella/apps/web_web/lib/web_web/views/error_helpers.ex
* creating web_umbrella/apps/web_web/lib/web_web/views/error_view.ex
* creating web_umbrella/apps/web_web/mix.exs
* creating web_umbrella/apps/web_web/README.md
* creating web_umbrella/apps/web_web/.gitignore
* creating web_umbrella/apps/web_web/test/test_helper.exs
* creating web_umbrella/apps/web_web/test/support/channel_case.ex
* creating web_umbrella/apps/web_web/test/support/conn_case.ex
* creating web_umbrella/apps/web_web/test/web_web/views/error_view_test.exs
* creating web_umbrella/apps/web_web/.formatter.exs
* creating web_umbrella/apps/web_web/lib/web_web/controllers/page_controller.ex
* creating web_umbrella/apps/web_web/lib/web_web/views/layout_view.ex
* creating web_umbrella/apps/web_web/lib/web_web/views/page_view.ex
* creating web_umbrella/apps/web_web/test/web_web/controllers/page_controller_test.exs
* creating web_umbrella/apps/web_web/test/web_web/views/page_view_test.exs
* creating web_umbrella/apps/web_web/assets/vendor/topbar.js
* creating web_umbrella/apps/web_web/lib/web_web/templates/layout/root.html.heex
* creating web_umbrella/apps/web_web/lib/web_web/templates/layout/app.html.heex
* creating web_umbrella/apps/web_web/lib/web_web/templates/layout/live.html.heex
* creating web_umbrella/apps/web_web/lib/web_web/templates/page/index.html.heex
* creating web_umbrella/apps/web_web/test/web_web/views/layout_view_test.exs
* creating web_umbrella/apps/web_web/lib/web_web/gettext.ex
* creating web_umbrella/apps/web_web/priv/gettext/en/LC_MESSAGES/errors.po
* creating web_umbrella/apps/web_web/priv/gettext/errors.pot
* creating web_umbrella/apps/web_web/assets/css/phoenix.css
* creating web_umbrella/apps/web_web/assets/css/app.css
* creating web_umbrella/apps/web_web/assets/js/app.js
* creating web_umbrella/apps/web_web/priv/static/robots.txt
* creating web_umbrella/apps/web_web/priv/static/images/phoenix.png
* creating web_umbrella/apps/web_web/priv/static/favicon.ico
* creating web_umbrella/apps/web/lib/web/application.ex
* creating web_umbrella/apps/web/lib/web.ex
* creating web_umbrella/apps/web/test/test_helper.exs
* creating web_umbrella/apps/web/README.md
* creating web_umbrella/apps/web/mix.exs
* creating web_umbrella/apps/web/.gitignore
* creating web_umbrella/apps/web/.formatter.exs
* creating web_umbrella/apps/web/lib/web/repo.ex
* creating web_umbrella/apps/web/priv/repo/migrations/.formatter.exs
* creating web_umbrella/apps/web/priv/repo/seeds.exs
* creating web_umbrella/apps/web/test/support/data_case.ex
* creating web_umbrella/apps/web/lib/web/mailer.ex

Fetch and install dependencies? [Yn] Y
* running mix deps.get
* running mix deps.compile

We are almost there! The following steps are missing:

    $ cd web_umbrella

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

Start your Phoenix app with:

    $ mix phx.server

You can also run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix phx.server

$ cd web_umbrella/apps/web_web/
$ mix phx.gen.live --no-context --no-schema --context-app web Foo Signup users
==> web
Compiling 4 files (.ex)
Generated web app
==> web_web
* creating lib/web_web/live/signup_live/show.ex
* creating lib/web_web/live/signup_live/index.ex
* creating lib/web_web/live/signup_live/form_component.ex
* creating lib/web_web/live/signup_live/form_component.html.heex
* creating lib/web_web/live/signup_live/index.html.heex
* creating lib/web_web/live/signup_live/show.html.heex
* creating test/web_web/live/signup_live_test.exs
* creating lib/web_web/live/modal_component.ex
* creating lib/web_web/live/live_helpers.ex
* injecting lib/web_web.ex

Add the live routes to your browser scope in lib/web_web/router.ex:

    live "/users", SignupLive.Index, :index
    live "/users/new", SignupLive.Index, :new
    live "/users/:id/edit", SignupLive.Index, :edit

    live "/users/:id", SignupLive.Show, :show
    live "/users/:id/show/edit", SignupLive.Show, :edit

@josevalim
Copy link
Member

I also could not reproduce this. Please reopen if it persists in more recent Phoenix versions. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants