Configuration
Learn more about how to configure Specify to generate design tokens and assets fitting your company standards.
Introduction
By default, without any parsers, Specify returns your design data as raw data:
Design tokens are returned in JSON
Assets are returned as files
A configuration file helps you:
request design tokens and assets from a Specify
repositorytransform them to fit your company standards thanks to rules, token types and parsers.
Properties
A configuration is composed of 3 main properties:
repositorypersonalAccessTokenrules
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:
module.exports = {
repository: '@acme-inc/all-design-data',
personalAccessToken: '<your-personal-access-token>',
rules: [],
};{
"repository": "@acme-inc/all-design-data",
"personalAccessToken": "<your-personal-access-token>",
"rules": []
}Personal Access Token
The Specify personalAccessToken used to authenticate your actions.
module.exports = {
repository: '@workspace/repository',
personalAccessToken: '<your-personal-access-token>',
rules: [],
};{
"repository": "@workspace/repository",
"personalAccessToken": "<your-personal-access-token>",
"rules": []
}Rules
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.
A rule is composed of the following properties:
interface Rule {
name: string;
path: string;
filter?: {
types: Array<TokenType>
};
parsers?: Array<Parser>;
};name
string
true
The name of your rule.
path
string
true
The path in your project where you want Specify to generate your design data.
If you want to pull bitmap, vector or font token types you must set a directory (Learn more ↗).
parsers
Array<Parser>
false
The parsers you want to apply to transform your Token types. For further details see Parsers.
Parsers
Parsers are functions allowing you to transform design tokens and assets coming from Specify to fit your needs and company standards.
Inside a configuration, a parser has the following properties:
interface Parser {
name: string;
options?: Record<string, any>;
}options
Record<string, any>false
The options relative to the parser you apply. Each parser has its own options you can find in their respective README file.
Example
Here's a rule named "Design Tokens" that:
targets
colorandmeasurementdesign tokenssorts them alphabetically by their
nametransforms them as CSS Custom Properties
writes them in a
design-tokens.cssfile inside astylesfolder
[
{
name: 'Design Tokens',
path: 'styles/design-tokens.css',
filter: {
types: ['color', 'measurement']
},
parsers: [
{
name: 'sort-by',
options: {
keys: ['name']
}
},
{
name: 'to-css-custom-properties'
}
]
},
][
{
"name": "Design Tokens",
"path": "styles/design-tokens.css",
"filter": {
"types": ["color", "measurement"]
},
"parsers": [
{
"name": "sort-by",
"options": {
"keys": ["name"]
}
},
{
"name": "to-css-custom-properties"
}
]
}
]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
a valid personal access token (Generate one ↗)
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 all-design-data from the @acme-inc organization:
{
"repository": "@acme-inc/all-design-data",
"personalAccessToken": "<your-personal-access-token>",
"rules": [
{
"name": "All design tokens in JSON",
"path": "design-tokens.json",
"parsers": []
}
]
}module.exports = {
repository: '@acme-inc/all-design-data',
personalAccessToken: '<your-personal-access-token>',
rules: [
{
name: 'All design tokens in JSON',
path: 'design-tokens.json',
parsers: [],
},
],
};This example config file will return a design-tokens.json file containing all design tokens and assets stored in the all-design-data repository.
Here's an example of a token value returned by Specify:
{
"id": String,
"createdAt": String,
"updatedAt": String,
"name": String,
"value": Object,
"meta": Object,
"type": String,
"originId": String,
"sourceId": String,
"description": String,
"repositoryId": String
}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 HSL.
module.exports = {
repository: '@acme-inc/all-design-data',
personalAccessToken: '<your-personal-access-token>',
rules: [
{
name: 'All design tokens in JSON',
path: 'colors.css',
filter: {
types: ['color']
},
parsers: [
{
name: 'to-css-custom-properties',
options: {
formatTokens: {
color: 'hsl'
},
},
},
],
},
],
};{
"repository": "@acme-inc/all-design-data",
"personalAccessToken": "<your-personal-access-token>",
"rules": [
{
"name": "Colors as CSS Custom Properties",
"path": "colors.css",
"filter": {
"types": ["color"]
},
"parsers": [
{
"name": "to-css-custom-properties",
"options": {
"formatTokens": {
"color": "hsl"
}
}
}
]
}
]
}Here is the input returned by Specify and the output generated by Specify after executing our configuration.
[
{
"name": "Primary/100",
"value": {
"a": 1,
"b": 254,
"g": 233,
"r": 237
},
"type": "color",
"description": ""
},
{
"name": "Primary/200",
"value": {
"a": 1,
"b": 254,
"g": 214,
"r": 221
},
"type": "color",
"description": ""
},
{
"name": "Primary/300",
"value": {
"a": 1,
"b": 253,
"g": 181,
"r": 196
},
"type": "color",
"description": ""
}
]:root {
/* COLOR */
--primary-100: hsl(251, 91%, 95%);
--primary-200: hsl(251, 95%, 92%);
--primary-300: hsl(252, 95%, 85%);
}Last updated
Was this helpful?