@estebanruano/design-tokens 1.0.4 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,80 +1,53 @@
1
1
  # Design System Tokens
2
2
 
3
- Single source of truth for all design tokens. One `pnpm run build` generates platform-specific outputs for Web, Android, iOS, Flutter, and Compose Multiplatform.
3
+ Single source of truth for all design tokens — **`figma/tokens.json`** (Tokens Studio / Figma Variables export) is the **absolute source of truth** on every branch, generated into `tokens/` and platform `dist/` outputs. Markdown-based syncing was removed; `design-system-foundations.md` is documentation only.
4
+
5
+ ## Documentation
6
+
7
+ | Guide | Audience |
8
+ |-------|----------|
9
+ | **[Figma SSOT](docs/figma-ssot.md)** | Figma JSON as source — `pnpm run sync:figma` |
10
+ | [Workflow & production](docs/workflow-and-production.md) | Releases (markdown-sync sections are historical) |
11
+ | [General next steps](docs/general-next-steps.md) | Platform leads — adopting tokens across web, mobile, Flutter |
12
+ | [Android + Material 3](docs/android-material3-next-steps.md) | Android / Compose — theme mapping |
13
+ | [design-system-foundations.md](design-system-foundations.md) | Designers — token values and naming (documentation) |
4
14
 
5
15
  ## Quick Start
6
16
 
7
17
  ```bash
8
18
  pnpm install
9
19
 
10
- # Full pipeline: markdown token JSONs all platform outputs
11
- pnpm run sync
12
-
13
- # Or run each step separately:
14
- pnpm run parse # markdown → token JSONs only
15
- pnpm run build # token JSONs → platform outputs only
20
+ # From Figma JSON (Tokens Studio export the SSOT):
21
+ pnpm run sync:figma
16
22
  ```
17
23
 
18
- Outputs land in `dist/` (Gradle uses `./build/`, so token outputs use `dist/` to avoid clashes):
24
+ | Command | Source | Generates |
25
+ |---------|--------|-----------|
26
+ | **`pnpm run sync:figma`** | `figma/tokens.json` | `tokens/`, `dist/**`, `package.json` ← `$metadata.version` |
19
27
 
20
- ```
21
- dist/
22
- ├── web/
23
- │ ├── tokens.css # CSS custom properties
24
- │ └── tokens.js # ES6 JavaScript constants
25
- ├── android/
26
- │ ├── colors.xml # Android color resources
27
- │ ├── dimens.xml # Android dimension resources
28
- │ └── font_dimens.xml # Android font dimensions
29
- ├── ios/
30
- │ └── DesignTokens.swift # Swift constants (UIColor)
31
- ├── flutter/
32
- │ └── design_tokens.dart # Dart constants (Color)
33
- ├── compose/
34
- │ └── DesignTokens.kt # Kotlin object (Compose Color/Dp)
35
- └── json/
36
- └── tokens.json # Flat JSON (debugging / other tools)
37
- ```
28
+ `pnpm run sync` is an alias for **`sync:figma`**.
38
29
 
39
- ## How It Works
30
+ ### Pipeline
40
31
 
41
- The pipeline has two stages:
42
-
43
- **Stage 1 — `pnpm run parse`** runs `md-to-tokens.mjs`, which reads `design-system-foundations.md`, copies the `**Version:**` semver into `package.json`, extracts every JSON code block, converts to DTCG format (`$value` / `$type`), and writes each token category to its own file under `tokens/`.
44
-
45
- **Stage 2 — `pnpm run build`** runs Style Dictionary, which reads all `tokens/**/*.json` files and generates platform-specific outputs in `dist/`.
46
-
47
- **`pnpm run sync`** runs both stages in sequence — this is the single command the design team needs.
48
-
49
- ### Workflow
32
+ **Figma everything**
50
33
 
51
34
  ```
52
- design-system-foundations.md ← Designers edit this (the human-readable source)
53
-
54
- ▼ pnpm run parse
55
- tokens/**/*.json ← DTCG-format JSON (auto-generated)
56
-
57
- ▼ pnpm run build
58
- dist/ ← Platform outputs (auto-generated; commit with PR)
59
- ├── web/tokens.css
60
- ├── web/tokens.js
61
- ├── android/colors.xml
62
- ├── android/dimens.xml
63
- ├── ios/DesignTokens.swift
64
- ├── flutter/design_tokens.dart
65
- ├── compose/DesignTokens.kt
66
- └── json/tokens.json
35
+ figma/tokens.json → pnpm run sync:figma → tokens/ + dist/
67
36
  ```
68
37
 
69
38
  ### Versioning (releases)
70
39
 
71
- Release numbers for **npm** (`@estebanruano/design-tokens`), **Android Maven** (`tokensVersion`), and the `version` field in `package.json` all come from the `**Version:** x.y.z` line at the top of `design-system-foundations.md`. **`pnpm run parse`** and **`pnpm run sync`** write that value into `package.json`; Gradle uses `package.json` when `-PtokensVersion` / `TOKENS_VERSION` are unset. Bump `**Version:**` for each release (npm and GitHub Packages reject duplicate versions).
40
+ Release numbers for **npm** (`@estebanruano/design-tokens`), **Android Maven** (`tokensVersion`), and the `version` field in `package.json` all come from the **`VERSION`** file at the repo root (single line, semver). `pnpm run version:set -- --version x.y.z` writes it (and mirrors it into the foundations md and `package.json`); **`pnpm run sync`** copies `VERSION` into `package.json`; Gradle reads `VERSION` when `-PtokensVersion` / `TOKENS_VERSION` are unset. Bump it for each release (npm and GitHub Packages reject duplicate versions).
72
41
 
73
- **Further reading:** [General next steps (all platforms)](docs/general-next-steps.md) · [Android + Material 3](docs/android-material3-next-steps.md)
42
+ **Further reading:** [Workflow & production](docs/workflow-and-production.md) · [General next steps](docs/general-next-steps.md) · [Android + Material 3](docs/android-material3-next-steps.md)
74
43
 
75
44
  ## Using tokens on the web
76
45
 
77
- Web artifacts are **`dist/web/tokens.css`** (CSS custom properties on `:root`) and **`dist/web/tokens.js`** (named ES module exports, e.g. `ColorPrimary500`). **`dist/json/tokens.json`** is a flat JSON dump for scripts or design tooling.
46
+ Web artifacts are **`dist/web/tokens.css`** (CSS custom properties on `:root`) and **`dist/web/tokens.js`** (named ES module exports). **`dist/figma/tokens.json`** is for Figma Variables / Tokens Studio import. **`dist/json/tokens.json`** is a flat Style Dictionary dump for scripts.
47
+
48
+ ### Figma
49
+
50
+ After `pnpm run figma` or `pnpm run sync`, import **`dist/figma/tokens.json`** in [Tokens Studio for Figma](https://tokens.studio/) (or your Variables sync plugin). Token names match Oter CSS variables (`primary-color`, `text-primary`, `type-h1`, …). Override the collection name with `FIGMA_COLLECTION="My Set"` if needed.
78
51
 
79
52
  ### In this monorepo / locally
80
53
 
@@ -97,7 +70,7 @@ import { ColorPrimary500, Spacing4 } from '@estebanruano/design-tokens';
97
70
  @import '@estebanruano/design-tokens/css';
98
71
 
99
72
  .my-button {
100
- background: var(--color-primary-500);
73
+ background: var(--color-brand-primary);
101
74
  padding: var(--spacing-4);
102
75
  }
103
76
  ```
@@ -115,10 +88,9 @@ Use the same **`import '@estebanruano/design-tokens/css'`** and **`import { …
115
88
 
116
89
  #### npm release checklist (maintainers)
117
90
 
118
- 1. Bump **`**Version:**`** in **`design-system-foundations.md`** (and merge so **`main`** has the release).
119
- 2. Run **`pnpm run sync`** locally or rely on CI / **Sync tokens from markdown** so **`package.json`**, **`tokens/`**, and **`dist/`** match the doc; commit any changes.
120
- 3. **First time only:** bootstrap the package with **`npm publish --access public`** from a machine logged into npm (see **[First publish on npm (bootstrap)](#first-publish-on-npm-bootstrap)**), then configure **Trusted publishing** on npm for workflow **`publish-web.yml`**.
121
- 4. **Ongoing:** GitHub → **Actions** → **Publish web tokens (npm)** → **Run workflow** on **`main`** (OIDC; no **`NPM_TOKEN`**).
91
+ 1. Bump the version locally: `pnpm run version:set -- --version 1.0.10` (writes **`VERSION`** and mirrors it into the foundations md + `package.json`), run `pnpm run sync:figma`, commit, push.
92
+ 2. GitHub **Actions** **Publish web tokens (npm)** or **Publish Android library** **Run workflow** on the branch to release (no inputs — the version is read from the **`VERSION`** file). Both sync from **`figma/tokens.json`** and build `dist/android/*.xml` for the AAR.
93
+ 3. **First time only (npm):** bootstrap with **`npm publish --access public`**, then configure **Trusted publishing** for **`publish-web.yml`** (see **[First publish on npm (bootstrap)](#first-publish-on-npm-bootstrap)**).
122
94
 
123
95
  ### Fetching without a package manager (CDN)
124
96
 
@@ -134,29 +106,34 @@ Pin the version in the URL for reproducible builds. For production SPAs, prefer
134
106
  ```
135
107
  tokens/
136
108
  ├── color/
137
- │ ├── primary.json # Brand primary scale (00–800)
138
- │ ├── secondary.json # Brand secondary scale (00–800)
139
- │ ├── neutral.json # Gray scale (0–1000)
140
- └── semantic.json # Success, warning, error, info
109
+ │ ├── brand.json # Indigo brand (primary, hover, tints)
110
+ │ ├── surface.json # Slate surfaces + borders
111
+ │ ├── text.json # Text ramp
112
+ ├── semantic.json # Success, warning, danger, info
113
+ │ ├── eisenhower.json # Tasks matrix accents
114
+ │ └── gradient.json # Auth hero gradient
141
115
  ├── typography/
142
- └── scale.json # Font families, weights, sizes, line heights
116
+ ├── family.json # Geist, Geist Mono, Lexend
117
+ │ ├── weight.json
118
+ │ └── scale.json # Semantic type scale (h1–mono)
143
119
  ├── spacing/
144
- │ └── spacing.json # 4px base unit scale (0–40)
120
+ │ └── spacing.json # xs xxl (4px base)
145
121
  ├── radius/
146
- │ └── radius.json # Border radii (none–full)
122
+ │ └── radius.json # sm full
147
123
  ├── shadow/
148
- │ └── shadow.json # Elevation levels (sm–xl)
124
+ │ └── shadow.json # sm xl
149
125
  ├── motion/
150
- └── motion.json # Duration + easing curves
151
- └── opacity/
152
- └── opacity.json # Disabled, hover, pressed, focus, scrim
126
+ ├── duration.json
127
+ └── easing.json
128
+ └── z-index/
129
+ └── z-index.json # Stacking ladder
153
130
  ```
154
131
 
155
132
  ## How to Update Tokens
156
133
 
157
134
  ### For engineers (Claude Code)
158
135
  ```bash
159
- claude "Update primary-500 to #EA580C in tokens/color/primary.json, rebuild, commit and push"
136
+ claude "Update primary-color to #4F46E5 in figma/tokens.json, run pnpm run sync, commit and push"
160
137
  ```
161
138
 
162
139
  ### For designers (GitHub Web UI)
@@ -170,78 +147,31 @@ claude "Update primary-500 to #EA580C in tokens/color/primary.json, rebuild, com
170
147
 
171
148
  ## Adding a New Token
172
149
 
173
- 1. Add the token to the appropriate JSON file under `tokens/`
174
- 2. Follow the DTCG-compatible format:
150
+ 1. Add the token to **`figma/tokens.json`** (flat Tokens Studio name) and map it in
151
+ `token-name-map.mjs` (`FIGMA_TO_TOKEN_PATH`) if the generic naming rules do not cover it:
175
152
  ```json
176
153
  {
177
154
  "token-name": {
178
155
  "$value": "#F97316",
179
- "$type": "color",
180
- "$description": "Optional description"
156
+ "$type": "color"
181
157
  }
182
158
  }
183
159
  ```
184
- 3. Run `pnpm run sync` to verify all platforms generate correctly
185
- 4. Commit and push — CI validates; merge to `main`, then run **Publish Android library** and/or **Publish web tokens (npm)** manually when you want a Maven or npm release (see below)
160
+ 2. Run `pnpm run sync` to verify all platforms generate correctly (never edit `tokens/` by hand)
161
+ 3. Commit and push — CI validates; merge to `main`, then run **Publish Android library** and/or **Publish web tokens (npm)** manually when you want a Maven or npm release (see below)
186
162
 
187
163
  ## Automation (GitHub Actions)
188
164
 
189
- This repo can run the full “edit markdown tokens PR → registries” loop on GitHub:
165
+ Full setup, branch flows, Figma in prod, release checklists, and troubleshooting: **[docs/workflow-and-production.md](docs/workflow-and-production.md)**.
190
166
 
191
167
  | Workflow | When | What it does |
192
168
  |----------|------|----------------|
193
- | **Sync tokens from markdown** | Push that changes `design-system-foundations.md` | Runs `pnpm run sync`, commits `tokens/`, `dist/`, and `package.json` (when changed) to the same branch, then opens a PR into `main` if the branch is not `main` and no open PR exists. On `main`, it pushes the sync commit directly. |
194
- | **CI** | Pull requests to `main` | `pnpm run sync` then fails if anything drifts from the commit; builds `:design-tokens-android` with Gradle. |
195
- | **Publish Android library** | Manual only: Actions → workflow → **Run workflow** (typically from `main`) | `pnpm run sync`, then `./gradlew :design-tokens-android:publish` to **GitHub Packages**. Maven **groupId**, **artifactId**, and Android **namespace** are set in **`gradle.properties`**. **Version** = `**Version:**` in `design-system-foundations.md` (via `package.json` after sync; override with `-PtokensVersion` / `TOKENS_VERSION` if needed). |
196
- | **Publish web tokens (npm)** | Manual only: Actions → workflow → **Run workflow** (typically from `main`) | `pnpm run sync`, then **`npm publish`** (npm ≥ 11.5.1) to **registry.npmjs.org** using **[Trusted Publishing](https://docs.npmjs.com/trusted-publishers/)** (OIDC). Requires **`id-token: write`** in the workflow (already set) and a one-time **Trusted Publisher** config on npm for workflow file **`publish-web.yml`**. **Version** comes from the foundations markdown (see **Versioning** above). |
197
-
198
- ### Deployment workflow
199
-
200
- Deployments are **manual** for Android (Maven) and web (npm). Nothing publishes automatically when you merge to `main`. Use this sequence when you want consumers to pick up a new release.
201
-
202
- **Workflow files** (under `.github/workflows/`):
203
-
204
- | File | Role |
205
- |------|------|
206
- | `sync-tokens-from-md.yml` | Regenerates artifacts after markdown edits (automatic on push). |
207
- | `ci.yml` | Validates PRs: regenerated tree must match the commit. |
208
- | `publish-android.yml` | Publishes the Android AAR to **GitHub Packages** (Maven). |
209
- | `publish-web.yml` | Publishes **`@estebanruano/design-tokens`** to **npm** via **OIDC** ([Trusted publishing](https://docs.npmjs.com/trusted-publishers/)). |
210
-
211
- **Recommended release path**
212
-
213
- 1. **Change tokens or version** in `design-system-foundations.md` (including `**Version:**` when you intend a new Maven/npm release — see **Versioning (releases)** above).
214
- 2. **Push** your branch. **Sync tokens from markdown** runs: it executes `pnpm run sync`, commits generated files, and either **opens a PR to `main`** (feature branches) or **pushes to `main`** (if you edited on `main` directly).
215
- 3. **Review and merge** the PR when CI is green (or confirm the direct push on `main` if you used that path).
216
- 4. **Publish** — only after `main` contains the version and artifacts you want live:
217
- - **Android:** GitHub → **Actions** → **Publish Android library** → **Run workflow**, select **`main`** (or a release branch if you use one). Uses `GITHUB_TOKEN`; no extra secret.
218
- - **Web:** GitHub → **Actions** → **Publish web tokens (npm)** → **Run workflow**, select **`main`**. Uses **OIDC trusted publishing** (no `NPM_TOKEN`); complete the [one-time npm setup](#npm-trusted-publishing-setup) below.
219
-
220
- Both publish workflows run **`pnpm run sync`** first, so the published bits always match the checked-out commit (including `**Version:**` → `package.json`). The npm job then runs **`npm publish`** so the npm CLI can use OIDC (see [Trusted publishing](https://docs.npmjs.com/trusted-publishers/)).
221
-
222
- **If publish fails with 409 / duplicate version**
223
-
224
- The Maven or npm coordinate for that version already exists. Bump `**Version:**` in the foundations doc, merge a sync commit, then run the publish workflow again.
225
-
226
- ```mermaid
227
- flowchart TD
228
- A[Edit design-system-foundations.md] --> B[Push]
229
- B --> C[Sync tokens from markdown]
230
- C --> D{Branch is main?}
231
- D -->|No| E[Bot commits + opens PR to main]
232
- D -->|Yes| F[Bot commits to main]
233
- E --> G[Merge PR after CI]
234
- F --> H[main up to date]
235
- G --> H
236
- H --> I[Run publish workflows from main when ready]
237
- I --> J[Publish Android library → GitHub Packages Maven]
238
- I --> K[Publish web tokens npm → registry.npmjs.org]
239
- ```
240
-
241
- **Repo settings you need**
169
+ | **Sync tokens from Figma JSON** | Push to `figma/tokens.json` (or manual) | `pnpm run sync:figma` commit `tokens/`, `dist/`, `package.json` |
170
+ | **CI** | PR to `main` / `belcorp` | `sync:figma` fail on drift assemble Android |
171
+ | **Publish web tokens (npm)** | Manual | `sync:figma` `npm publish` |
172
+ | **Publish Android library** | Manual | `sync:figma` Gradle publish |
242
173
 
243
- 1. **Actions General Workflow permissions**: allow **Read and write** so the sync job can push commits and open PRs.
244
- 2. **Android publishing**: GitHub Packages Maven uses `GITHUB_TOKEN` from Actions (`packages: write` on the Android publish workflow). Bump `**Version:**` in `design-system-foundations.md` for every new Maven release — **the same version cannot be published twice** (Gradle will fail with **HTTP 409 Conflict** if you try).
174
+ Merging to `main` does **not** publish npm or Maven run publish workflows when consumers need a new version.
245
175
 
246
176
  #### npm: Trusted publishing setup
247
177
 
@@ -308,9 +238,24 @@ In **CI** for the consuming app, inject the same values (e.g. repository secrets
308
238
 
309
239
  ### Using tokens in Android app code
310
240
 
311
- The **`tokens-android`** artifact is a normal **`com.android.library`**: it ships **resource XML** only (colors, dimens, font dimens, etc.). After `implementation(...)`, those resources are **merged** into your app module, so you reference them like any other library resource.
241
+ The **`tokens-android`** artifact is a normal **`com.android.library`**: it ships **resource XML** only. After `implementation(...)`, those resources are **merged** into your app module, so you reference them like any other library resource.
242
+
243
+ **Local repo vs published AAR:** this repo keeps **four** files under `dist/android/` (`colors.xml`, `dimens.xml`, `integers.xml`, `strings.xml`). Android Studio often shows them as **one combined `<resources>` block** when you inspect the library dependency — that is normal. If colors or `font_size_*` differ from your local `dist/android/`, the app is almost certainly on an **older Maven version**; bump the dependency and re-run **Publish Android library** with a new version after `pnpm run sync`.
244
+
245
+ **Resource names** match the generated files in **`dist/android/`**: `colors.xml`, `dimens.xml` (spacing, radius, **and font sizes in `sp`**), `integers.xml`, `strings.xml`. There is no `R.font_dimens` type — font sizes are normal **`R.dimen`** entries (e.g. `R.dimen.font_size_h1`, `@dimen/font_size_h1` in XML).
312
246
 
313
- **Resource names** match the generated files in this repo under **`dist/android/`** (e.g. `colors.xml`, `dimens.xml`). Typical names look like `color_primary_500`, `color_neutral_500`, `spacing_4`, `radius_md` — always confirm the exact `name="…"` in those files when you add or rename tokens.
247
+ **Font sizes in Compose:** `dimensionResource()` returns `Dp`, but `Text.fontSize` needs `TextUnit` (`sp`). Use:
248
+
249
+ ```kotlin
250
+ import androidx.compose.ui.platform.LocalDensity
251
+ import androidx.compose.ui.res.dimensionResource
252
+
253
+ Text(
254
+ fontSize = with(LocalDensity.current) {
255
+ dimensionResource(R.dimen.font_size_h1).toSp()
256
+ },
257
+ )
258
+ ```
314
259
 
315
260
  **XML layouts**
316
261
 
@@ -318,8 +263,9 @@ The **`tokens-android`** artifact is a normal **`com.android.library`**: it ship
318
263
  <TextView
319
264
  android:layout_width="wrap_content"
320
265
  android:layout_height="wrap_content"
321
- android:textColor="@color/color_primary_500"
322
- android:padding="@dimen/spacing_4" />
266
+ android:textColor="@color/color_brand_primary"
267
+ android:textSize="@dimen/font_size_body"
268
+ android:padding="@dimen/spacing_md" />
323
269
  ```
324
270
 
325
271
  **`styles.xml` / Material theme**
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.32