DalaNew.LiveViewGenerator (dala_new v0.4.0)

Copy Markdown View Source

Generates a LiveView-wrapped Dala project.

This module owns everything specific to the --liveview path:

  1. Runs mix phx.new as a subprocess
  2. Patches mix.exs to add the dala / dala_dev dependencies
  3. Copies the native Android/iOS boilerplate, skipping Phoenix-owned files (see DalaNew.ProjectGenerator.liveview_phoenix_owned?/3)
  4. Applies the Dala bridge patches (DalaHook, dala-bridge element, DalaScreen, dala.exs, Erlang bootstrap, port alignment, notes starter app)

On failure the partially-created project directory is removed so a retry doesn't hit "Directory already exists".

Summary

Functions

Generates a LiveView project at dest_dir/<app_name>.

When generating a LiveView project, mix phx.new already produced its own mix.exs, config/, lib/<app>/, lib/<app>_web/, .gitignore, and assets/ — and those are the correct versions for a Phoenix app (with gettext, telemetry_metrics, etc.). The native template's same-named files are written for the bare-Dala path and would clobber Phoenix's, leaving the project unable to compile.

Functions

generate(app_name, dest_dir \\ ".", opts \\ [])

@spec generate(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Generates a LiveView project at dest_dir/<app_name>.

Returns {:ok, project_dir} or {:error, reason}.

liveview_phoenix_owned?(path, root, opts)

@spec liveview_phoenix_owned?(String.t(), String.t(), keyword()) :: boolean()

When generating a LiveView project, mix phx.new already produced its own mix.exs, config/, lib/<app>/, lib/<app>_web/, .gitignore, and assets/ — and those are the correct versions for a Phoenix app (with gettext, telemetry_metrics, etc.). The native template's same-named files are written for the bare-Dala path and would clobber Phoenix's, leaving the project unable to compile.

When :liveview is true in opts, this predicate returns true for any template path that Phoenix already owns, so the copy step skips it. Files that are unique to Dala (dala.exs, src/<app>.erl, android/, ios/) still get emitted normally.

Public for testing — guards against the regression where a new template path lands in the native tree without being added to the LiveView blocklist.