Introduction
Whenever you want to work with the or the destination, you need to create a Configuration file to instruct the how to transform your design data, so it generate tokens that match your technical requirements.
A configuration file helps you:
request design tokens and assets from a Specify repository
transform them to fit your company standards thanks to
Properties
A configuration is composed of 3 main properties:
Repository
The name of the Specify repository
you want to pull your design tokens and assets from.
Let's say we have the following repository in Specify called "all-design-data" located in the "@acme-inc" organization.
We target it like this:
JavaScript (CommonJS) JSON
Copy module.exports = {
version: '2'
repository: '@acme-inc/all-design-data-v2',
personalAccessToken: '<your-personal-access-token>',
rules: [],
};
Copy {
"version": "2"
"repository": "@acme-inc/all-design-data-v2",
"personalAccessToken": "<your-personal-access-token>",
"rules": []
}
Personal Access Token
The Specify personalAccessToken
used to authenticate you.
JavaScript (CommonJS) JSON
Copy module.exports = {
version: '2'
repository: '@workspace/repository',
personalAccessToken: '<your-personal-access-token>',
rules: [],
};
Copy {
"version": "2"
"repository": "@workspace/repository",
"personalAccessToken": "<your-personal-access-token>",
"rules": []
}
Parser Rules
The Parsers Rules help you transform your design tokens and assets the way you want.
You can have as many rules
as you want and you can have rules that transform several Token types at once.
Here are different kind of rules and parsers you can use to generate color tokens as CSS Custom Properties:
JavaScript (CommonJS) JSON
Copy {
version: '2',
repository: '@organization/repository',
personalAccessToken: '<your-personal-access-token>',
rules: [
{
name: 'css',
parsers: [
{
name: 'filter',
options: {
query: {
where: {
collection: '^Colors$',
select: {
children: true
}
}
}
}
},
{
name: 'convert-color',
options: {
toFormat: 'hsl',
applyTo: {
collection: true
}
}
},
{
name: 'change-case',
options: {
change: 'names',
toCase: 'kebabCase',
applyTo: {
collection: true
}
}
},
{
name: 'change-case',
options: {
change: 'modes',
toCase: 'kebabCase',
applyTo: {
collection: true
}
}
},
{
name: 'to-css-custom-properties',
output: {
type: 'file',
filePath: 'tokens.css'
},
},
],
},
],
};
Copy {
"version": "2",
"repository": "@organization/repository",
"personalAccessToken": "<your-personal-access-token>",
"rules": [
{
"name": "css",
"parsers": [
{
"name": "filter",
"options": {
"query": {
"where": {
"collection": "Colors",
"select": {
"parents": true,
"children": true
}
}
}
}
},
{
"name": "convert-color",
"options": {
"toFormat": "hsl",
"applyTo": {
"collection": true
}
}
},
{
"name": "change-case",
"options": {
"change": "names",
"toCase": "kebabCase",
"applyTo": {
"collection": true
}
}
},
{
"name": "change-case",
"options": {
"change": "modes",
"toCase": "kebabCase",
"applyTo": {
"collection": true
}
}
},
{
"name": "to-css-custom-properties",
"output": {
"type": "file",
"filePath": "tokens.css"
}
}
]
}
]
}
Examples
How to run these examples
The following examples are made to be used with the Specify CLI.
Requirements:
a Specify repository containing design tokens
Run all examples by copying the code and running the specify pull
command.
Basic
Here's a basic configuration file that targets a Specify repository called design-system
from the @acme-inc
organization:
JavaScript (CommonJS) JSON
Copy module.exports = {
version: '2',
repository: '@acme-inc/design-system',
personalAccessToken: '<your-personal-access-token>',
rules: [
{
name: 'Generate colors as CSS Custom Properties',
parsers: [
{
name: 'to-css-custom-properties',
output: {
type: 'file',
filePath: 'colors.css'
},
},
],
},
],
};
Copy {
"version": "2",
"repository": "@acme-inc/color-themes",
"personalAccessToken": "<your-personal-access-token>",
"rules": [
{
"name": "Generate colors as CSS Custom Properties",
"parsers": [
{
"name": "to-css-custom-properties",
"output": {
"type": "file",
"filePath": "colors.css"
}
}
]
}
]
}
This example config file will return a colors.css
file containing all design tokens stored in the design-system
repository.
Here's an example of a token value returned by Specify:
Copy {
"colors": {
"$collection": {
"$modes": [
"Light",
"Dark"
]
},
"core": {
"blue-100": {
"$type": "color",
"$description": "token 1 aliased with n modes within collection within n groups",
"$value": {
"Light": {
"red": 219,
"blue": 254,
"alpha": 1,
"green": 236,
"model": "rgb"
}
}
}
}
}
}
Pull colors as CSS Custom Properties
Now let's update our previous configuration to only pull colors and transform them as CSS Custom Properties in RGB.
JavaScript (CommonJS) JSON
Copy module.exports = {
version: '2',
repository: '@acme-inc/design-system',
personalAccessToken: '<your-personal-access-token>',
rules: [
{
name: 'Generate colors as CSS Custom Properties',
parsers: [
{
name: 'convert-color',
options: {
toFormat: 'rgb',
applyTo: {
collection: true
}
}
},
{
name: 'to-css-custom-properties',
output: {
type: 'file',
filePath: 'colors.css'
},
options: {
tokenNameTemplate: '--{{groups}}-{{token}}',
selectorTemplate: '[data-theme=\'{{mode}}\']',
includeCoreTokensInScopes: true
},
},
],
},
],
};
Copy
{
"version": "2",
"repository": "@acme-inc/design-system",
"personalAccessToken": "<your-personal-access-token>",
"rules": [
{
"name": "Generate colors as CSS Custom Properties",
"parsers": [
{
"name": "convert-color",
"options": {
"toFormat": "rgb",
"applyTo": {
"collection": true
}
}
},
{
"name": "to-css-custom-properties",
"output": {
"type": "file",
"filePath": "colors.css"
},
"options": {
"tokenNameTemplate": "--{{groups}}-{{token}}",
"selectorTemplate": "[data-theme=\"{{mode}}\"]",
"includeCoreTokensInScopes": true
}
}
]
}
]
}
Here is the input returned by Specify and the output generated by Specify after executing our configuration.
Input (Before) Output (After)
Copy [data-theme="dark"] {
--core-blue-100: rgb(41, 52, 67);
--core-blue-700: rgb(96, 168, 250);
--semantic-background-button-primary-hover: var(--core-blue-100);
}
[data-theme="light"] {
--core-blue-100: rgb(219, 236, 254);
--core-blue-700: rgb(17, 125, 249);
--semantic-background-button-primary-hover: var(--core-blue-700);
}