mix caravela.gen.live (Caravela v0.13.3)

Copy Markdown View Source

Generates the full Svelte frontend layer for a Caravela domain:

  • a trio of Phoenix LiveView modules (index / show / form) per frontend: :live entity

  • a Phoenix controller per frontend: :rest entity

  • typed Svelte components for every entity (same component tree under both render modes)

  • a TypeScript interfaces file per domain

  • ExUnit + Vitest test skeletons (opt out with --no-tests)

    mix caravela.gen.live MyApp.Domains.Library

Generated files (single-version, non-tenant example with one :live entity and one :rest entity):

lib/my_app_web/live/library/book_live/{index,show,form}.ex
lib/my_app_web/controllers/article_controller.ex
assets/svelte/library/{BookIndex,BookShow,BookForm}.svelte
assets/svelte/library/{ArticleIndex,ArticleShow,ArticleForm}.svelte
assets/svelte/library/*.test.ts
assets/svelte/types/library.ts
test/my_app_web/live/library/book_live_test.exs
test/my_app_web/controllers/article_controller_test.exs

Every LiveView and controller mounts / renders its Svelte component via caravela_svelte (both <CaravelaSvelte.svelte> for :live and CaravelaSvelte.render/3 for :rest), and delegates to the generated context module for CRUD calls — authorization, hooks, and multi-tenant scoping flow through for free.

Requires caravela_svelte in the consumer app:

{:caravela_svelte, "~> 0.1"}

After mix deps.get, follow the caravela_svelte docs to wire the client runtime into assets/js/app.js.

Flags:

  • --dry-run — print the generated files without writing
  • --output DIR — write under DIR instead of the project root
  • --force — overwrite existing files without prompting
  • --with-domain — also emit a Caravela.Live.Domain companion module per :live entity and generate form.ex from the Template-backed variant. Useful as an onramp to the Caravela.Live.* runtime.
  • --frontend MODE — override the render transport for every entity in the domain. MODE is live (LiveView + WebSocket) or rest (Inertia-style HTTP via caravela_svelte). Without the flag, each entity's DSL-declared frontend: is used, defaulting to :live.
  • --no-tests — skip generating ExUnit + Vitest test skeletons. By default the generator emits one <entity>_live_test.exs per :live entity, one <entity>_controller_test.exs per :rest entity, and one *.test.ts colocated next to each Svelte file. Tests use standard Phoenix / Vitest idioms and carry # TODO: lines where fixtures need to be filled in.

Router registration

The task prints a one-line hint pointing at Caravela.Router. Drop use Caravela.Router + caravela_routes MyApp.Domains.X into your router and every route for every entity expands at compile time — no paste-snippet necessary. See Caravela.Router for the full API.

Regeneration preserves content below the # --- CUSTOM --- / <!-- --- CUSTOM --- --> marker in every file.