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

Copy Markdown View Source

Generates the frontend layer for a Caravela domain: a trio of LiveView modules (index/show/form) per entity, plus typed Svelte components and a TypeScript interfaces file.

mix caravela.gen.live MyApp.Domains.Library

Generated files (single-version, non-tenant example):

lib/my_app_web/live/library/book_live/{index,show,form}.ex
assets/svelte/library/{BookIndex,BookShow,BookForm}.svelte
assets/svelte/types/library.ts

Every LiveView mounts its Svelte component via <LiveSvelte.svelte>, and delegates to the generated context module for CRUD calls — authorization, hooks, and multi-tenant scoping flow through for free.

Requires LiveSvelte in the consumer app:

{:live_svelte, "~> 0.19"}

After mix deps.get, follow the LiveSvelte docs to wire it 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 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 (today's LiveView + WebSocket path) or rest (Inertia-style SSR via caravela_svelte). Without the flag, each entity's DSL-declared frontend: is used, defaulting to :live.

Entities declared with frontend: :rest skip LiveView generation — Caravela prints a caravela_rest router snippet instead. Svelte components are emitted for both modes (the component contract is mode-agnostic).

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