Skip to content

feat: add mint-ds apply to codemod source CSS to tokens (#35)#97

Merged
nujovich merged 3 commits into
mainfrom
feat/apply-codemod-pr
Jul 20, 2026
Merged

feat: add mint-ds apply to codemod source CSS to tokens (#35)#97
nujovich merged 3 commits into
mainfrom
feat/apply-codemod-pr

Conversation

@nujovich

Copy link
Copy Markdown
Owner

Closes #35. Adds mint-ds apply <path> — the final step of the pipeline: audit → curate → export → apply.

What it does

Rewrites raw color/spacing/font-family values in source CSS/SCSS to reference the generated design-token CSS variables, so adopting the tokens becomes a reviewable migration commit instead of manual find-and-replace.

mint-ds apply <path> [--tokens f] [--fuzzy] [--dry-run] [--force] [--target css-var]
  • Deterministic, no LLM: the raw value → token map is derived locally by normalizing each literal and matching it against the tokens file (colors against the 50–900 scale, spacing against the scale, font-family exact).
    • color: #1976d2var(--color-primary); other shades → var(--color-primary-600).
    • Format-normalized: #1976D2, rgb(25, 118, 210) all match.
    • padding: 8pxvar(--spacing-2); font-family: Inter, sans-serifvar(--font-body).
  • --fuzzy (opt-in): snaps near-duplicate colors / off-scale spacing to the nearest token with a /* was 13px */ comment. Off by default → exact-only is zero-false-positive.
  • Writes in place, guarded by a git-clean check: refuses to overwrite files with uncommitted changes (or that git can't verify) unless --force. --dry-run previews without writing.
  • Safe: skips comments / url() / existing var(), never node_modules, only source extensions, fully idempotent.
  • --target css-var only in slice 1 (the flag errors on other values). CSS-in-JS / tailwind targets are deferred.

Design & scope

Spec and slice-1 boundaries are in docs/superpowers/specs/2026-07-17-mint-apply-codemod-design.md. Known slice-1 limitations (documented + tested): HTML <style> blocks are rewritten but inline style="..." attributes are not; the emitted var names follow the export prompt's naming convention (drift risk noted).

New modules (all added to published files + guarded by check:pack)

lib/css-values.mjs, lib/token-index.mjs, lib/css-codemod.mjs, lib/git-status.mjs.

Testing

Built test-first (TDD). 47 feature tests + full suite green; check:pack green; verified end-to-end on a real tokens file.

nujovich added 3 commits July 17, 2026 16:15
Deterministic, no-LLM codemod that rewrites raw color/spacing/font-family
values in source CSS to reference the generated design-token CSS variables.
Exact matches always; near-duplicate/off-scale snaps behind --fuzzy (with
/* was X */ comments). Writes in place, guarded by a git-clean check
(--force bypasses). Skips comments/url()/var(), never node_modules, only
source extensions, idempotent. --target css-var only in slice 1.

New modules: lib/css-values.mjs, lib/token-index.mjs, lib/css-codemod.mjs,
lib/git-status.mjs (all added to published files + check:pack).
@nujovich
nujovich merged commit 3a8cd52 into main Jul 20, 2026
2 checks passed
@nujovich
nujovich deleted the feat/apply-codemod-pr branch July 20, 2026 15:42
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]: mint-ds apply — codemod source CSS to use the generated tokens

1 participant