Configuration file 101

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

Introduction

Whenever you want to work with the GitHub or the Specify CLI destination, you need to create a Configuration file to instruct the Parsers Engine how to transform your design data, so it generate tokens that match your technical requirements.

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 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 = {
  version: '2'
  repository: '@acme-inc/all-design-data-v2',
  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 several configuration files and run them with the Specify CLI (See example script).

Personal Access Token

The Specify personalAccessToken used to authenticate you.

Need a personal access token? Generate one ↗

module.exports = {
  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.

Looking for the rules configuration? 👉 review the Parser Rule reference.

Here are different kind of rules and parsers you can use to generate color tokens as CSS Custom Properties:

  1. filter to target on a specific collection named "Colors" that contains our colors

  2. convert-color to convert our colors in HSL

  3. change-case to change the name of our tokens and modes to kebabCase

  4. to-css-custom-properties to generate a CSS file containing our tokens

.specifyrc.js
{
  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'
          },
        },
      ],
    },
  ],
};

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 design-system from the @acme-inc organization:

.specifyrc.js
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'
          },
        },
      ],
    },
  ],
};

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:

{
  "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.

.specifyrc.js
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
          },
        },
      ],
    },
  ],
};

Here is the input returned by Specify and the output generated by Specify after executing our configuration.

{
  "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"
          },
          "Dark": {
            "red": 41,
            "blue": 67,
            "alpha": 1,
            "green": 52,
            "model": "rgb"
          }
        }
      },
      "blue-700": {
        "$type": "color",
        "$description": "token 2 aliased with n modes within collection within n groups",
        "$value": {
          "Light": {
            "red": 17,
            "blue": 249,
            "alpha": 1,
            "green": 125,
            "model": "rgb"
          },
          "Dark": {
            "red": 96,
            "blue": 250,
            "alpha": 1,
            "green": 168,
            "model": "rgb"
          }
        }
      }
    },
    "semantic": {
      "background": {
        "button": {
          "primary": {
            "hover": {
              "$type": "color",
              "$description": "alias token with n modes within collection within n groups",
              "$value": {
                "Dark": {
                  "$mode": "dark",
                  "$alias": "colors.core.blue-100"
                },
                "Light": {
                  "$mode": "light",
                  "$alias": "colors.core.blue-700"
                }
              }
            }
          }
        }
      }
    }  
  }
}

Last updated