Skip to main content

Crate plumb_codegen

Crate plumb_codegen 

Source
Expand description

§plumb-codegen

Source-tree token inference for Plumb. Walks a project directory, discovers design-token sources (CSS custom properties, Tailwind config files, DTCG token JSON), and bootstraps a best-effort plumb_core::Config.

Consumers (plumb-cli’s init --from <path> command) call infer_config to walk the tree and render_toml to serialize the result. Both are deterministic: identical inputs produce byte-identical output across runs and platforms.

§Inference sources (V0)

  • CSS custom properties. Every :root { --token: value; } declaration discovered under src/, styles/, app/, or the project root is classified by name into the spacing, color, radius, and type-scale buckets. Implementation lives in plumb_config::scrape_css_properties.
  • Tailwind config files. Presence of tailwind.config.{js,ts, mjs,cjs,mts,cts} is recorded in the rendered TOML’s header comment so the user knows to wire extends once that landed. The crate never spawns Node; full Tailwind theme resolution is handled at lint time by plumb_config::merge_tailwind.
  • DTCG token JSON files. Files matching *.tokens.json or placed under a tokens/ directory are merged via plumb_config::merge_dtcg.

§Determinism contract

  • Directory entries are sorted by their canonical UTF-8 path before recursion. The walker visits files in the same order on every filesystem.
  • Scales (spacing.scale, radius.scale, type.scale) are sorted ascending and deduplicated.
  • Tokens land in indexmap::IndexMap in discovery order; insertion order is preserved by serde during TOML serialization.
  • The walker never reads SystemTime / Instant. The error surface never carries a wall-clock value.

Structs§

InferredConfig
Result of walking a source tree. The Config field is populated with whatever tokens the inference passes were able to recover; the summary field records, in stable order, what each pass discovered so the CLI can surface a one-line note per source.
TokenSource
One discovered token-source file.

Enums§

CodegenError
Codegen errors.
TokenSourceKind
Kind of a discovered token source. Used to drive both the renderer’s header comment and the per-source summary order.

Constants§

MAX_WALK_DEPTH
Maximum directory depth the walker descends into the source tree.

Functions§

infer_config
Walk source_dir and infer a plumb_core::Config from the design-token sources it finds.
render_toml
Render inferred to a TOML string.