Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V1
V1
  • Getting started
    • Introduction
    • What is Specify?
    • Getting started
    • Glossary
  • Advanced Repository
    • Getting started
    • Figma Variables & Styles
    • Tokens Studio
    • CLI & Config
    • Querying a SDTF graph
    • GitHub
    • Parsers
      • to-css-custom-properties
      • to-style-dictionary
      • to-tailwind
      • to-sdtf
      • to-javascript
      • to-react-native
      • to-json
      • to-typescript
      • filter
      • select-modes
      • change-case
      • convert-color
      • convert-dimension
    • Templates
      • CSS Custom Properties
      • SDTF
      • Tailwind
    • REST API
    • Playground
  • Concepts
    • Token types
    • Configuration
    • Parsers
    • Templates
    • Best practices
  • Apps & Tools
    • Overview
    • GitHub
    • npm
    • GitLab
    • Bitbucket
    • Azure DevOps
    • REST API
    • CLI
    • Notion
    • Raycast
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
Powered by GitBook
On this page
  • Introduction
  • Properties
  • Repository
  • Personal Access Token
  • Rules
  • Examples
  • How to run these examples
  • Basic
  • Pull colors as CSS Custom Properties

Was this helpful?

Edit on GitHub
Export as PDF
  1. Concepts

Configuration

Learn more about how to configure Specify to generate design tokens and assets fitting your company standards.

PreviousToken typesNextParsers

Last updated 1 year ago

Was this helpful?

Introduction

By default, without any , Specify returns your design data as raw data:

  • Design tokens are returned in JSON

  • Assets are returned as files

A configuration file helps you:

  1. request design tokens and assets from a Specify repository

  2. transform them to fit your company standards thanks to rules, token types and parsers.

Properties

A configuration is composed of 3 main properties:

  • repository

  • personalAccessToken

  • rules

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:

.specifyrc.js
module.exports = {
  repository: '@acme-inc/all-design-data',
  personalAccessToken: '<your-personal-access-token>',
  rules: [],
};
.specifyrc.json
{
  "repository": "@acme-inc/all-design-data",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": []
}

You can only target one repository per configuration file. Want to pull design tokens from several Specify repositories? Create a several configuration files and run them with the Specify CLI.

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.

A rule is composed of the following properties:

interface Rule {
  name: string;
  path: string;
  filter?: {
    types: Array<TokenType>
  };
  parsers?: Array<Parser>;
};
Name
Type
Required
Description

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.

filter

false

parsers

Array<Parser>

false

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>;
}
Name
Type
Required
Description

name

string

true

options

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:

  1. targets color and measurement design tokens

  2. sorts them alphabetically by their name

  3. transforms them as CSS Custom Properties

  4. writes them in a design-tokens.css file inside a styles folder

.specifyrc.js
[
  {
    name: 'Design Tokens',
    path: 'styles/design-tokens.css',
    filter: {
      types: ['color', 'measurement']
    },
    parsers: [
      {
        name: 'sort-by',
        options: {
          keys: ['name']
        }
      },
      {
        name: 'to-css-custom-properties'
      }
    ]
  },
]
.specifyrc.json
[
  {
    "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

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:

.specifyrc.json
{
  "repository": "@acme-inc/all-design-data",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "All design tokens in JSON",
      "path": "design-tokens.json",
      "parsers": []
    }
  ]
}
.specifyrc.js
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.

.specifyrc.js
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'
            },
          },
        },
      ],
    },
  ],
};
.specifyrc.json
{
  "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": ""
  }
]
colors.css
:root {
  /* COLOR */
  --primary-100: hsl(251, 91%, 95%);
  --primary-200: hsl(251, 95%, 92%);
  --primary-300: hsl(252, 95%, 85%);
}

Need a personal access token?

You can have as many rules as you want and you can have rules that transform several at once.

If you want to pull , or token types you must set a directory ().

The list of you want your rule to target.

The parsers you want to apply to transform your . For further details see .

The name of the parser. Choose from .

a valid personal access token ()

Record<'types', Array<TokenType>>
Record<string, any>
Generate one ↗
Token types
Generate one ↗
Token type
Token types
Parsers
parsers
Learn more ↗
all available parsers
An example Specify repository called "all-design-data" located in the "@acme-inc" organization.
An example Specify repository called 'all-design-data' located in the '@acme-inc' organization.
bitmap
vector
font