A system that processes design tokens from Tokens Studio for Figma and transforms them into CSS files.
This project uses the Tokens Studio for Figma plugin as the primary method for managing design tokens. Here's why:
The Figma API, while powerful for many use cases, has several limitations when it comes to design tokens:
-
Incomplete Token Data:
- Only provides basic style information
- Missing computed values and references
- No support for token relationships
- Limited metadata and documentation
-
Missing Features:
- No token versioning
- Limited support for nested tokens
- No built-in token validation
- Missing token usage context
-
Data Structure Issues:
- Inconsistent formatting
- Partial token sets
- Missing style definitions
- No support for token aliases
Tokens Studio provides a complete solution for design token management:
-
Complete Token System:
- Full token definitions
- Computed values
- Token relationships
- Metadata and documentation
-
Consistent Output:
- Standardized formatting
- Complete token sets
- Proper value handling
- Consistent naming
-
Better Integration:
- Direct GitHub integration
- PR-based workflow
- Change tracking
- Version control
The recommended workflow is:
- Use Tokens Studio in Figma to manage tokens
- Push changes to GitHub via the plugin
- Let the GitHub Action process the tokens
- Review and merge changes
This approach ensures we have complete, consistent, and well-managed design tokens.
-
Token Updates:
- Tokens Studio creates a PR when changes are pushed
- PR includes the updated
design-tokens.json
file - GitHub Action automatically triggers on PR creation
-
Action Processing:
- Action checks out the PR branch
- Processes the token file
- Generates CSS variables
- Updates the PR with processed files
-
File Management:
- Original
design-tokens.json
is preserved - Processed files are added to the PR:
design_tokens.json
(processed version)design_tokens.css
(CSS variables)
- Original
-
Branch Structure:
main
: Production-ready tokens- Feature branches: Created by Tokens Studio
- No long-lived branches needed
-
Naming Conventions:
- Feature branches:
tokens/description
- PR titles:
Update Design Tokens: Description
- Commit messages:
Update design tokens
- Feature branches:
-
Conflict Resolution:
- Always rebase on latest
main
- Resolve conflicts in Tokens Studio
- Push resolved changes to update PR
- Always rebase on latest
-
Required Secrets:
SLACK_WEBHOOK_URL: # For notifications FIGMA_ACCESS_TOKEN: # For validation
-
Permissions:
permissions: contents: write pull-requests: write
-
Triggers:
on: pull_request: branches: - main paths: - 'design-tokens.json'
-
PR Checklist:
- Token changes are valid
- CSS generation successful
- No conflicts with existing tokens
- Documentation updated if needed
-
Validation Steps:
- Check token counts
- Verify CSS output
- Review change comments
- Test in preview if available
-
Common Issues:
- Missing token references
- Invalid token values
- CSS generation errors
- Merge conflicts
-
PR Comments:
- Token change summary
- Processing results
- Validation status
- Next steps
-
Change Tracking:
- Token additions/removals
- Value changes
- CSS variable updates
- Version history
-
Rollback Process:
- Revert PR if needed
- Restore previous version
- Update Tokens Studio
- Create new PR with fixes
-
Action Failures:
- Check action logs
- Verify secrets
- Review token file
- Test locally
-
PR Issues:
- Branch conflicts
- Permission errors
- Processing failures
- Validation errors
-
Debug Steps:
# Test locally npm run process-tokens -- --input design-tokens.json --output ./output # Check logs cat output/design_tokens.json cat output/design_tokens.css
-
Common Solutions:
- Update branch from main
- Fix token references
- Adjust permissions
- Clear action cache
-
Token Update Flow:
sequenceDiagram participant TS as Tokens Studio participant GH as GitHub participant GA as GitHub Action participant PR as Pull Request TS->>GH: Push token changes GH->>PR: Create PR PR->>GA: Trigger action GA->>PR: Process tokens GA->>PR: Add processed files GA->>PR: Add comment PR->>GH: Ready for review
-
Branch Structure:
graph TD A[main] --> B[Feature Branch] B --> C[PR] C --> D[Processed Files] D --> E[Review] E -->|Approved| A E -->|Rejected| B
-
Action Process:
flowchart LR A[PR Created] --> B[Checkout Branch] B --> C[Process Tokens] C --> D[Generate CSS] D --> E[Update PR] E --> F[Add Comment] F --> G[Complete]
-
Review Process:
flowchart TD A[PR Created] --> B{Valid Tokens?} B -->|Yes| C{Valid CSS?} B -->|No| D[Fix in TS] C -->|Yes| E{No Conflicts?} C -->|No| F[Fix Processing] E -->|Yes| G[Approve] E -->|No| H[Resolve Conflicts] D --> A F --> A H --> A
These diagrams show:
- The sequence of events in the token update process
- How branches interact and merge
- The steps in the GitHub Action
- The review and approval workflow
- Processes design tokens from Tokens Studio output
- Transforms tokens into CSS variables with utility classes
- Integrates with GitHub repositories for version control
- Automated processing via GitHub Actions
- Detects changes to avoid unnecessary updates
- Node.js (v14 or higher)
- GitHub repository
- Tokens Studio for Figma plugin
-
Clone this repository:
git clone https://github.com/eGovPDX/design-tokens.git cd design-tokens
-
Install dependencies:
npm install
-
Configure GitHub repository:
- Set up GitHub Actions secrets if needed
- Configure Tokens Studio to push to your repository
Process tokens from a local file:
npm run process-tokens -- --input design-tokens.json --output ./output
The included GitHub Action will:
- Trigger when Tokens Studio creates a PR
- Process the design tokens
- Update the PR with processed files
- Add a comment with processing details
src/tokenProcessor.js
: Processes design tokens from filessrc/tokenTransformer.js
: Transforms tokens into CSS variables.github/workflows/process-tokens.yml
: GitHub Action workflowoutput/
: Directory for processed files
The processed tokens are saved in JSON format with the following structure:
{
"colors": {
"primary": "#000000",
"secondary": "#ffffff"
},
"typography": {
"heading-1": {
"fontFamily": "Inter",
"fontSize": 32,
"fontWeight": 700
}
},
"spacing": {
"small": 8,
"medium": 16,
"large": 24
}
}
The tokens are transformed into CSS variables:
:root {
/* Colors */
--color-primary-blue: #0066cc;
--color-secondary-green: #00cc66;
/* Typography */
--typography-heading-h1-font-family: Roboto;
--typography-heading-h1-font-size: 32px;
--typography-heading-h1-font-weight: 700;
--typography-heading-h1-line-height: 1.2;
/* Spacing */
--spacing-small: 8px;
--spacing-medium: 16px;
}
/* Utility classes are also generated */
You can customize the path where tokens are saved in the GitHub repository by modifying the workflow file.
Modify the transformToCss
method in the TokenTransformer
class to change the CSS output format.
- Verify that the input file is valid JSON
- Check that the file structure matches the expected format
- Ensure all required token types are present
- Check workflow permissions
- Verify repository secrets
- Review action logs for errors
MIT