Skip to content

feat: add CSS custom properties export format (--format css-vars) - #109

Merged
davideast merged 1 commit into
google-labs-code:mainfrom
mvanhorn:feat/15-css-vars-export-format
Jul 1, 2026
Merged

davideast merged 1 commit into
google-labs-code:mainfrom
mvanhorn:feat/15-css-vars-export-format

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Adds a css-vars export target so design.md export --format css-vars DESIGN.md emits a :root { ... } block of CSS custom properties derived from the token set. This makes DESIGN.md tokens directly consumable in native-CSS codebases without Tailwind or any token tooling.

Why this matters

Issue #15 asks for a CSS variables export so DESIGN.md is useful outside the Tailwind ecosystem and gives coding agents a direct artifact to apply in native CSS. It complements the existing dtcg and Tailwind exports. Scope here is the core format plus --prefix; dark-theme / media-query variants are deferred as the issue notes.

Changes

  • New emitter under packages/cli/src/linter/css-vars/ (spec.ts, handler.ts, serialize.ts) following the DtcgEmitterHandler pattern: a pure execute(state) maps colors, spacing, and rounded to --<group>-<name> declarations, and serializeCssVars renders the :root block.
  • Wired into export.ts: css-vars added to the FORMATS enum, a new branch mirroring the other formats, and an optional --prefix arg threaded into the serializer (default emits --color-...).
  • Re-exported the handler, serializer, and result type from linter/index.ts.
  • Nested token keys flatten to dotted names (e.g. background.light); those dots are collapsed to hyphens so the emitted property name is valid CSS.

Sample output (--prefix ds):

:root {
  --ds-color-surface: #f9f9ff;
  --ds-spacing-unit: 8px;
  --ds-rounded-sm: 0.25rem;
}

Testing

  • bun test in packages/cli: 289 pass, 1 skip, 0 fail
  • bun run lint (tsc --noEmit): clean
  • New unit tests cover colors, spacing/rounded units, --prefix, nested-name hyphenation, and empty input; a command-level test covers a --format css-vars round-trip plus the invalid-format exit-code-1 path.

Fixes #15

@rajpratham1 rajpratham1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a well-scoped feature that introduces a new css-vars export format without disrupting the existing export pipeline. The implementation follows the same architecture as the existing emitters, includes comprehensive unit tests, and exposes the functionality cleanly through the CLI.

@davideast davideast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mvanhorn!

@davideast
davideast merged commit ea4a324 into google-labs-code:main Jul 1, 2026
8 checks passed
davideast pushed a commit that referenced this pull request Jul 14, 2026
The success branches (css-tailwind, json-tailwind, dtcg, css-vars) write
their output but never assign process.exitCode, so a successful export
left the code at its incoming value instead of an explicit 0. That is the
success-path counterpart to #126, which decoupled the exit code from
source lint findings; the subprocess test there only exercises json-tailwind
and a real process happens to exit 0 when exitCode is unset, so the gap went
unnoticed. Set process.exitCode = 0 after the format branches (every error
branch already returns first).

The in-process export.test.ts added in #109 asserts process.exitCode === 0
after a css-vars export, so it was failing on main. Also fix a companion
assertion in that file: it read error.error for the human message, but the
error envelope is { error: CODE, message: TEXT }, so the text lives on
error.message.

Signed-off-by: Arpit Jain <[email protected]>
@davideast davideast mentioned this pull request Jul 27, 2026
wang-junjian pushed a commit to wang-junjian/design.md that referenced this pull request Nov 23, 2026
wang-junjian pushed a commit to wang-junjian/design.md that referenced this pull request Nov 23, 2026
…#152)

The success branches (css-tailwind, json-tailwind, dtcg, css-vars) write
their output but never assign process.exitCode, so a successful export
left the code at its incoming value instead of an explicit 0. That is the
success-path counterpart to google-labs-code#126, which decoupled the exit code from
source lint findings; the subprocess test there only exercises json-tailwind
and a real process happens to exit 0 when exitCode is unset, so the gap went
unnoticed. Set process.exitCode = 0 after the format branches (every error
branch already returns first).

The in-process export.test.ts added in google-labs-code#109 asserts process.exitCode === 0
after a css-vars export, so it was failing on main. Also fix a companion
assertion in that file: it read error.error for the human message, but the
error envelope is { error: CODE, message: TEXT }, so the text lives on
error.message.

Signed-off-by: Arpit Jain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: add CSS custom properties export (--format css-vars) for native CSS consumers

3 participants