PhoenixAssets.Typespec (PhoenixAssets v0.1.0)

View Source

Integration plugin that generates TypeScript from Elixir typespecs.

PhoenixAssets.Types covers Ash resources. This covers everything else a backend already describes in a @type — a streaming protocol, a job status union, an event payload — so a host stops hand-writing the TypeScript twin of a type it has already declared.

Declare each contract under the :stack config:

config :phoenix_assets, :stack,
  typespecs: [
    [
      source: MyApp.Stream.Part,
      output: "stream-part.ts",
      root: :t,
      root_name: "StreamPart",
      discriminator_name: "StreamPartKind"
    ]
  ]

source and output are required; output is relative to the generated directory. The remaining keys are PhoenixAssets.Generators.Typespec options: types (declaration order, defaulting to every type sorted), root, root_name, discriminator_name, and trailer.

Why a plugin

Generators.Typespec can write a file on its own, and a host calling it from a Mix task gets none of what the rest of the pipeline provides: the write is not content-gated, so every run touches the file and triggers an HMR reload; mix phoenix_assets.gen --check cannot see it, so the CI drift gate silently skips it; and the output is absent from the asset graph. Going through the plugin puts typespec contracts on the same footing as every other one.

Summary

Functions

dev_processes(_, _)

Callback implementation for PhoenixAssets.Plugin.dev_processes/2.

name()

Callback implementation for PhoenixAssets.Plugin.name/0.

vite_config(_, _)

Callback implementation for PhoenixAssets.Plugin.vite_config/2.