Automated design token syncing between Figma Token Studio and your codebase with built-in analytics
- π Automatic Token Syncing - Real-time sync from Figma Token Studio to code
- π¨ Multi-Format Output - CSS variables, Tailwind config, TypeScript definitions, SCSS
- π Built-in Analytics - Track token usage and generate insights
- π Smart Validation - Comprehensive token validation with helpful warnings
- π CI/CD Ready - GitHub Actions workflows and git automation
- β‘ Hot Reload - Watch mode for development
- ποΈ Framework Agnostic - Works with React, Vue, Next.js, and more
npm install --save-dev design-tokens-sync
- Initialize in your project:
npx design-tokens-sync init
- Start syncing tokens:
npm run tokens:sync
- Watch for changes during development:
npm run tokens:watch
# Initialize design tokens setup
npx design-tokens-sync init
# Sync tokens once
npx design-tokens-sync sync
# Watch for changes
npx design-tokens-sync watch
# Validate tokens
npx design-tokens-sync validate
# Generate analytics report
npx design-tokens-sync analytics report
# Show current configuration
npx design-tokens-sync config
import designTokensSync from 'design-tokens-sync';
// Sync tokens programmatically
await designTokensSync.sync({
configPath: './design-tokens.config.js'
});
// Validate tokens
const validation = await designTokensSync.validate('./tokens.json');
console.log(validation.isValid ? 'β
Valid' : 'β Invalid');
// Generate analytics
const analytics = await designTokensSync.analytics.collect();
const report = await designTokensSync.analytics.report();
Create a design-tokens.config.js
file in your project root:
module.exports = {
tokens: {
input: 'tokens.json',
validation: {
required: ['colors'],
optional: ['spacing', 'typography', 'borderRadius']
}
},
output: {
css: 'src/styles/tokens.css',
tailwind: 'tailwind.config.js',
typescript: 'src/types/tokens.d.ts',
scss: 'src/styles/_tokens.scss'
},
git: {
enabled: true,
autoCommit: true,
autoPush: false,
commitMessage: 'π¨ Update design tokens'
},
analytics: {
enabled: true,
autoCollect: true
},
watch: {
enabled: true,
ignore: ['node_modules', '.git', 'dist', 'build']
}
};
Supports both Token Studio and standard JSON formats:
{
"$themes": [],
"$metadata": {
"tokenSetOrder": ["core", "semantic"]
},
"core": {
"colors": {
"primary": {
"500": {
"value": "#3b82f6",
"type": "color",
"description": "Primary brand color"
}
}
},
"spacing": {
"4": {
"value": "1rem",
"type": "spacing"
}
}
}
}
{
"colors": {
"primary": {
"500": "#3b82f6"
}
},
"spacing": {
"4": "1rem"
}
}
:root {
/* Colors */
--color-primary-500: #3b82f6;
/* Spacing */
--spacing-4: 1rem;
}
export default {
theme: {
extend: {
colors: {
primary: {
500: '#3b82f6'
}
},
spacing: {
4: '1rem'
}
}
}
};
export interface Colors {
primary: {
"500": string;
};
}
export interface DesignTokens {
colors: Colors;
spacing: Record<string, string>;
}
Track token usage across your codebase:
# Collect usage data
npx design-tokens-sync analytics collect
# Generate report
npx design-tokens-sync analytics report --format html
# Export to CSV
npx design-tokens-sync analytics report --format csv
Analytics features:
- Usage Tracking - Find which tokens are used where
- Unused Token Detection - Identify tokens that can be removed
- Adoption Metrics - Track design system adoption
- Trend Analysis - Monitor token usage over time
Automatically sync tokens when tokens.json
changes:
name: Design Tokens Sync
on:
push:
paths: ['tokens.json']
jobs:
sync-tokens:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: npm ci
- run: npm run tokens:sync
- run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git diff --staged --quiet || git commit -m "π¨ Update design tokens"
git push
The init
command automatically adds these scripts:
{
"scripts": {
"tokens:sync": "design-tokens-sync sync",
"tokens:watch": "design-tokens-sync watch",
"tokens:validate": "design-tokens-sync validate",
"tokens:analytics": "design-tokens-sync analytics report"
}
}
The package consists of several core modules:
- TokenProcessor - Loads, transforms, and processes tokens
- TokenValidator - Validates token structure and values
- FileGenerator - Generates output files in multiple formats
- GitManager - Handles version control operations
- AnalyticsEngine - Tracks usage and generates reports
// After running tokens:sync, use tokens in your components
function Button({ variant = 'primary' }) {
return (
<button className={`bg-${variant}-500 text-white px-4 py-2`}>
Click me
</button>
);
}
.button {
background-color: var(--color-primary-500);
padding: var(--spacing-4);
border-radius: var(--border-radius-md);
}
import type { DesignTokens } from './types/tokens';
// Fully typed token access
const theme: DesignTokens = {
colors: {
primary: { 500: '#3b82f6' }
}
};
Ensure your tokens file exists and the path in design-tokens.config.js
is correct:
module.exports = {
tokens: {
input: './path/to/your/tokens.json' // Update this path
}
};
If you're getting git errors, check your configuration:
module.exports = {
git: {
enabled: false // Disable git operations
}
};
Try excluding problematic directories:
module.exports = {
watch: {
ignore: ['node_modules', '.git', 'dist', 'build', '.next']
}
};
Make sure your TypeScript configuration includes the generated types:
{
"compilerOptions": {
"types": ["./src/types/tokens.d.ts"]
}
}
Enable verbose logging:
DEBUG=design-tokens-sync npx design-tokens-sync sync
- Update configuration format:
// Old format (0.x)
module.exports = {
input: 'tokens.json',
output: 'tokens.css'
};
// New format (1.x)
module.exports = {
tokens: { input: 'tokens.json' },
output: { css: 'tokens.css' }
};
- CLI command changes:
# Old commands
npx figma-tokens-sync
# New commands
npx design-tokens-sync sync
- Add to package.json:
{
"scripts": {
"tokens:sync": "design-tokens-sync sync",
"dev": "design-tokens-sync watch & next dev"
}
}
- Set up GitHub Actions:
npx design-tokens-sync init --github-actions
// design-tokens.config.js
module.exports = {
output: {
css: 'app/globals.css',
tailwind: 'tailwind.config.js',
typescript: 'types/tokens.d.ts'
}
};
module.exports = {
output: {
css: 'src/styles/tokens.css',
typescript: 'src/types/tokens.d.ts'
},
watch: {
ignore: ['dist', 'node_modules']
}
};
module.exports = {
output: {
javascript: 'src/design-tokens.js', // React Native compatible
typescript: 'src/types/tokens.d.ts'
}
};
module.exports = {
tokens: {
validation: {
custom: {
'colors': (value) => /^#[0-9A-F]{6}$/i.test(value),
'spacing': (value) => value.endsWith('rem') || value.endsWith('px')
}
}
}
};
module.exports = {
hooks: {
beforeSync: async (tokens) => {
console.log('About to sync', Object.keys(tokens).length, 'tokens');
},
afterSync: async (results) => {
console.log('Sync complete!', results);
}
}
};
module.exports = {
output: {
css: [
'src/styles/tokens.css',
'public/tokens.css'
],
tailwind: 'tailwind.config.js',
typescript: 'src/types/tokens.d.ts',
json: 'dist/tokens.json'
}
};
import { TokenProcessor } from 'design-tokens-sync/core';
const processor = new TokenProcessor({
configPath: './design-tokens.config.js'
});
// Load and parse tokens
const tokens = await processor.loadTokens();
// Transform tokens
const transformed = processor.transformTokens(rawTokens);
// Sync tokens
await processor.sync();
import { AnalyticsEngine } from 'design-tokens-sync/analytics';
const analytics = new AnalyticsEngine();
// Collect usage data
const usage = await analytics.collectUsage('./src');
// Generate report
const report = await analytics.generateReport(usage);
- Use semantic naming:
color-brand-primary
instead ofcolor-blue-500
- Group related tokens: Keep spacing, colors, typography organized
- Document token purpose: Use descriptions in Token Studio
- Development: Use watch mode for real-time updates
- CI/CD: Validate tokens before syncing
- Production: Use git hooks to prevent inconsistencies
- Designers update tokens in Figma Token Studio
- Export tokens.json from Token Studio
- Commit tokens.json to repository
- CI/CD automatically syncs and deploys changes
- Developers pull latest changes and get updated tokens
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/sixi3/design-tokens-sync.git
cd design-tokens-sync
npm install
npm run test
npm run build
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # With coverage
MIT Β© sixi3
Made with β€οΈ for design systems teams