Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page
  • Overview
  • Setup
  • CLI
  • SDK
  • Running a parser
  • CLI
  • SDK
  • Filtering the tokens
  • CLI
  • SDK
  • Updating tokens
  • CLI
  • SDK
  • Converting a token to a specific format
  • CLI
  • SDK

Was this helpful?

Export as PDF
  1. Resources

Specify CLI VS Specify SDK

PreviousJSONNextPlayground

Last updated 1 year ago

Was this helpful?

TL;DR - The CLI is faster to get started, but the SDK is more flexible and can match exactly what you need

Historically, if you wanted to convert your tokens to various outputs: , , ... you could only distribute your tokens thanks to a configuration file. With the introduction of the , you might want to know which option suits your needs, so let's compare them!

This page will be an overview of both options, so if you need more details, you can have look to the page, and the page.

Overview

Specify CLI
Specify SDK

Running parsers remotely

✅

✅

Running parsers locally

❌

✅

Update the tokens

✅

✅

Filter the tokens

✅

✅

Converting a token to a specific format

❌

✅

Create a custom output

❌

✅

Setup

CLI

In the case of the CLI, you'll first need to install the CLI:

npm install @specifyapp/cli 
yarn global add @specifyapp/cli

And then create a .specifyrc.json :

{
  "version": "2",
  "repository": "@organization/repository",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": []
}

SDK

npm install -D @specifyapp/sdk1.0.0-beta.5 @specifyapp/specify-design-token-format
yarn install -D @specifyapp/sdk @specifyapp/sdtf

Then you, you have to create a file where we'll import all the installed dependencies:

import { createSpecifyClient } from '@specifyapp/sdk';

async function run() {
  const specifyClient = createSpecifyClient();

  await specifyClient.authenticate('<your-personal-access-token>');
  
  const sdtfClient = specifyClient.getSDTFClientByName('<repository-name>');
}

run()

Running a parser

CLI

We first need to fill up a bit the configuration file with the parser we want to run:

{
  "version": "2",
  "repository": "@organization/repository",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Tokens as CSS Variables",
      "parsers": [
        {
          "name": "to-css-custom-properties",
          "output": {
            "type":"file",
            "filePath": "tokens.css"
          }
        }
      ]
    }
  ]
}

Then we can run everything through the CLI:

specify pull

SDK

On the SDK side, there's two way of doing it.

Running parsers locally

The main interest of the SDK is to be able to run everything locally. To do so, you can do the following:

import { createSpecifyClient, createSpecifyFileSystemHelper } from '@specifyapp/sdk';
import { toCssCustomProperties } from '@specifyapp/sdk/next';

async function run() {
  const specifyClient = createSpecifyClient();

  await specifyClient.authenticate('<your-personal-access-token>');
  
  const sdtfClient = specifyClient.getSDTFClientByName('<repository-name>');
  
  const generatorPipelineOutput = await sdtfClient.createParserPipeline(
    toCssCustomProperties({ filePath: 'myFile.css' }),
  );
  
  const fileSystemHelper = createSpecifyFileSystemHelper({ generatorPipelineOutput });
  
  await fileSystemHelper.writeToDisk('./rootFolder');
}

run()

Running parsers remotely

Running parsers remotely is basically wrapping the configuration into the SDK:

import { createSpecifyClient, createSpecifyFileSystemHelper } from '@specifyapp/sdk';

async function run() {
  const specifyClient = createSpecifyClient();

  await specifyClient.authenticate('<your-personal-access-token>');
  
  const sdtfClient = specifyClient.getSDTFClientByName('<repository-name>');
  
  const pipeEngineRuleResponseBody = await sdtfClient.transformWithRemoteParsers([
    {
      name: 'to-css-custom-properties',
      output: {type: 'file', filePath: 'tokens.css'},
    },
  ]);
  
  const fileSystemHelper = createSpecifyFileSystemHelper({
    pipeEngineRuleResponseBody
  });
  
  const writtenFiles = await fileSystemHelper.writeToDisk('./public');
}

run()

Filtering the tokens

CLI

To do so, we'll need to introduce a new parser in the configuration file:

{
  "version": "2",
  "repository": "@organization/repository",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Tokens as CSS Variables",
      "parsers": [
        {
          "name": "filter",
          "options": {
            "where": {
              "collection": "colors",
              "select": {
                "collection": true,
                "children": {
                  "tokens": true
                }
              }
            }
          }
        },
        {
          "name": "to-css-custom-properties",
          "output": {
            "type":"file",
            "filePath": "tokens.css"
          }
        }
      ]
    }
  ]
}

SDK

Because the SDK is loading the SDTF, we can work directly with it. No need to run a parser, we can just execute filtering methods, and then generate our tokens:

import { createSpecifyClient, createSpecifyFileSystemHelper } from '@specifyapp/sdk';
import { toCssCustomProperties } from '@specifyapp/sdk/next';

async function run() {
  const specifyClient = createSpecifyClient();

  await specifyClient.authenticate('<your-personal-access-token>');
  
  const sdtfClient = specifyClient.getSDTFClientByName('<repository-name>');
  
  const filteredGraph = sdtfClient.query({
    where: {
      collection: "colors",
      select: {
        collection: true,
        children: {
          tokens: true
        }
      }
    }
  });
  
  const generatorPipelineOutput = await filteredGraph
    .createParserPipeline(
      toCssCustomProperties({ filePath: 'myFile.css' }),
    )
    .execute();
  
  const fileSystemHelper = createSpecifyFileSystemHelper({ generatorPipelineOutput });
  
  await fileSystemHelper.writeToDisk('./rootFolder');
}

run()

Updating tokens

CLI

Just like before, it can be done through a parser:

{
  "version": "2",
  "repository": "@organization/repository",
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Tokens as CSS Variables",
      "parsers": [
        {
          "name": "convert-color",
          "options": {
            "toFormat": "hex"
          }
        },
        {
          "name": "to-css-custom-properties",
          "output": {
            "type":"file",
            "filePath": "tokens.css"
          }
        }
      ]
    }
  ]
}

SDK

import { createSpecifyClient, createSpecifyFileSystemHelper } from '@specifyapp/sdk';
import { toCssCustomProperties, updaters } from '@specifyapp/sdk/next';

async function run() {
  const specifyClient = createSpecifyClient();

  await specifyClient.authenticate('<your-personal-access-token>');
  
  const sdtfClient = specifyClient.getSDTFClientByName('<repository-name>');
  
  sdtfClient.update(
    updaters.color({ toFormat: 'hex' }, { where: { token: '^theme', select: true }})
  );
  
  const generatorPipelineOutput = await filteredGraph
    .createParserPipeline(
      toCssCustomProperties({ filePath: 'myFile.css' }),
    )
    .execute();
  
  const fileSystemHelper = createSpecifyFileSystemHelper({ generatorPipelineOutput });
  
  await fileSystemHelper.writeToDisk('./rootFolder');
}

run()

Converting a token to a specific format

CLI

This cannot be done with the CLI.

SDK

import { createSpecifyClient } from '@specifyapp/sdk';
import {
  dimensionToCss,
  breakpointToCss,
  colorToCss,
  createResolveAliasStrategy 
} from '@specify/sdk/css'

async function run() {
  const specifyClient = createSpecifyClient();

  await specifyClient.authenticate('<your-personal-access-token>');
  
  const sdtfClient = specifyClient.getSDTFClientByName('<repository-name>');
  
  const strategy = createResolveAliasStrategy()

  const outputs = sdtfClient.mapTokenStates(tokenState => 
    tokenState.matchByType(
      {
        dimension: dimensionToCss(strategy) // Output example: '12px'
        breakpoint: breakpointToCss(strategy) // Output example: '12px'
        color: colorToCss(strategy) // Output example: '#ff00ff'
      }, 
      _ => undefined
    )
  )
}

run()

For the SDK, you'll first want to install the dependencies of the SDK, and the :

There's actually a way to choose which parser runs locally, and which one runs remotely, you can learn more about it .

Again, as the SDK is loading the SDTF, we can work directly with it through the update method and an :

Here is an example of converting a token to CSS, more detals on the conversion can be found .

CSS
Swift
Typescript
SDK
Specify CLI
Specify SDK
SDTF
here
updater
here