@estebanruano/design-tokens 1.0.3 → 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,78 +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
16
- ```
17
-
18
- Outputs land in `dist/` (Gradle uses `./build/`, so token outputs use `dist/` to avoid clashes):
19
-
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)
20
+ # From Figma JSON (Tokens Studio export the SSOT):
21
+ pnpm run sync:figma
37
22
  ```
38
23
 
39
- ## How It Works
40
-
41
- The pipeline has two stages:
24
+ | Command | Source | Generates |
25
+ |---------|--------|-----------|
26
+ | **`pnpm run sync:figma`** | `figma/tokens.json` | `tokens/`, `dist/**`, `package.json` ← `$metadata.version` |
42
27
 
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/`.
28
+ `pnpm run sync` is an alias for **`sync:figma`**.
44
29
 
45
- **Stage 2 — `pnpm run build`** runs Style Dictionary, which reads all `tokens/**/*.json` files and generates platform-specific outputs in `dist/`.
30
+ ### Pipeline
46
31
 
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).
41
+
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)
72
43
 
73
44
  ## Using tokens on the web
74
45
 
75
- 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.
76
51
 
77
52
  ### In this monorepo / locally
78
53
 
@@ -95,7 +70,7 @@ import { ColorPrimary500, Spacing4 } from '@estebanruano/design-tokens';
95
70
  @import '@estebanruano/design-tokens/css';
96
71
 
97
72
  .my-button {
98
- background: var(--color-primary-500);
73
+ background: var(--color-brand-primary);
99
74
  padding: var(--spacing-4);
100
75
  }
101
76
  ```
@@ -113,10 +88,9 @@ Use the same **`import '@estebanruano/design-tokens/css'`** and **`import { …
113
88
 
114
89
  #### npm release checklist (maintainers)
115
90
 
116
- 1. Bump **`**Version:**`** in **`design-system-foundations.md`** (and merge so **`main`** has the release).
117
- 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.
118
- 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`**.
119
- 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)**).
120
94
 
121
95
  ### Fetching without a package manager (CDN)
122
96
 
@@ -132,29 +106,34 @@ Pin the version in the URL for reproducible builds. For production SPAs, prefer
132
106
  ```
133
107
  tokens/
134
108
  ├── color/
135
- │ ├── primary.json # Brand primary scale (00–800)
136
- │ ├── secondary.json # Brand secondary scale (00–800)
137
- │ ├── neutral.json # Gray scale (0–1000)
138
- └── 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
139
115
  ├── typography/
140
- └── 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)
141
119
  ├── spacing/
142
- │ └── spacing.json # 4px base unit scale (0–40)
120
+ │ └── spacing.json # xs xxl (4px base)
143
121
  ├── radius/
144
- │ └── radius.json # Border radii (none–full)
122
+ │ └── radius.json # sm full
145
123
  ├── shadow/
146
- │ └── shadow.json # Elevation levels (sm–xl)
124
+ │ └── shadow.json # sm xl
147
125
  ├── motion/
148
- └── motion.json # Duration + easing curves
149
- └── opacity/
150
- └── opacity.json # Disabled, hover, pressed, focus, scrim
126
+ ├── duration.json
127
+ └── easing.json
128
+ └── z-index/
129
+ └── z-index.json # Stacking ladder
151
130
  ```
152
131
 
153
132
  ## How to Update Tokens
154
133
 
155
134
  ### For engineers (Claude Code)
156
135
  ```bash
157
- 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"
158
137
  ```
159
138
 
160
139
  ### For designers (GitHub Web UI)
@@ -168,78 +147,31 @@ claude "Update primary-500 to #EA580C in tokens/color/primary.json, rebuild, com
168
147
 
169
148
  ## Adding a New Token
170
149
 
171
- 1. Add the token to the appropriate JSON file under `tokens/`
172
- 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:
173
152
  ```json
174
153
  {
175
154
  "token-name": {
176
155
  "$value": "#F97316",
177
- "$type": "color",
178
- "$description": "Optional description"
156
+ "$type": "color"
179
157
  }
180
158
  }
181
159
  ```
182
- 3. Run `pnpm run sync` to verify all platforms generate correctly
183
- 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)
184
162
 
185
163
  ## Automation (GitHub Actions)
186
164
 
187
- 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)**.
188
166
 
189
167
  | Workflow | When | What it does |
190
168
  |----------|------|----------------|
191
- | **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. |
192
- | **CI** | Pull requests to `main` | `pnpm run sync` then fails if anything drifts from the commit; builds `:design-tokens-android` with Gradle. |
193
- | **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). |
194
- | **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). |
195
-
196
- ### Deployment workflow
197
-
198
- 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.
199
-
200
- **Workflow files** (under `.github/workflows/`):
201
-
202
- | File | Role |
203
- |------|------|
204
- | `sync-tokens-from-md.yml` | Regenerates artifacts after markdown edits (automatic on push). |
205
- | `ci.yml` | Validates PRs: regenerated tree must match the commit. |
206
- | `publish-android.yml` | Publishes the Android AAR to **GitHub Packages** (Maven). |
207
- | `publish-web.yml` | Publishes **`@estebanruano/design-tokens`** to **npm** via **OIDC** ([Trusted publishing](https://docs.npmjs.com/trusted-publishers/)). |
208
-
209
- **Recommended release path**
210
-
211
- 1. **Change tokens or version** in `design-system-foundations.md` (including `**Version:**` when you intend a new Maven/npm release — see **Versioning (releases)** above).
212
- 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).
213
- 3. **Review and merge** the PR when CI is green (or confirm the direct push on `main` if you used that path).
214
- 4. **Publish** — only after `main` contains the version and artifacts you want live:
215
- - **Android:** GitHub → **Actions** → **Publish Android library** → **Run workflow**, select **`main`** (or a release branch if you use one). Uses `GITHUB_TOKEN`; no extra secret.
216
- - **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.
217
-
218
- 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/)).
219
-
220
- **If publish fails with 409 / duplicate version**
221
-
222
- 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.
223
-
224
- ```mermaid
225
- flowchart TD
226
- A[Edit design-system-foundations.md] --> B[Push]
227
- B --> C[Sync tokens from markdown]
228
- C --> D{Branch is main?}
229
- D -->|No| E[Bot commits + opens PR to main]
230
- D -->|Yes| F[Bot commits to main]
231
- E --> G[Merge PR after CI]
232
- F --> H[main up to date]
233
- G --> H
234
- H --> I[Run publish workflows from main when ready]
235
- I --> J[Publish Android library → GitHub Packages Maven]
236
- I --> K[Publish web tokens npm → registry.npmjs.org]
237
- ```
238
-
239
- **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 |
240
173
 
241
- 1. **Actions General Workflow permissions**: allow **Read and write** so the sync job can push commits and open PRs.
242
- 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.
243
175
 
244
176
  #### npm: Trusted publishing setup
245
177
 
@@ -302,11 +234,28 @@ gpr.key=YOUR_PAT_WITH_read:packages
302
234
 
303
235
  In **CI** for the consuming app, inject the same values (e.g. repository secrets mapped to env vars or `ORG_GRADLE_PROJECT_gpr.*` so Gradle picks them up).
304
236
 
237
+ **Material 3 and multi-project structure:** see [docs/android-material3-next-steps.md](docs/android-material3-next-steps.md) for mapping tokens to M3 (Compose + Views), shared theme libraries vs apps, and flavors / multiple products.
238
+
305
239
  ### Using tokens in Android app code
306
240
 
307
- 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).
308
246
 
309
- **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
+ ```
310
259
 
311
260
  **XML layouts**
312
261
 
@@ -314,8 +263,9 @@ The **`tokens-android`** artifact is a normal **`com.android.library`**: it ship
314
263
  <TextView
315
264
  android:layout_width="wrap_content"
316
265
  android:layout_height="wrap_content"
317
- android:textColor="@color/color_primary_500"
318
- 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" />
319
269
  ```
320
270
 
321
271
  **`styles.xml` / Material theme**
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.32