Skip to content

Using the CLI

The Style Dictionary command line interface (CLI) provides an executable system to create and act upon style dictionaries.

Installation

To use the CLI, you can install it globally via npm:

Terminal window
npm install -g style-dictionary

Most of the time you will want to install Style Dictionary as a dev dependency in your NPM package. The reason to have it as a dev dependency rather than a regular dependency is that Style Dictionary is a build tool rather than a runtime tool because it is used to generate files rather than used directly in an application.

Terminal window
npm install --save-dev style-dictionary

In your package.json file you can add an NPM script that runs Style Dictionary:

package.json
{
"scripts": {
"build": "style-dictionary build"
}
}

Commands

The CLI provides three basic commands:

  • build Builds a Style Dictionary package from the current directory.
  • clean Removes files specified in the config of the Style Dictionary package of the current directory.
  • init Generates a starter Style Dictionary
  • version Get the version of Style Dictionary

These commands can be run using:

Terminal window
style-dictionary [command] [options]

build

Builds a style dictionary package from the current directory. Usage:

Terminal window
style-dictionary build [options]

Options:

NameUsageDescription
Configuration Path-c , —config Set the path to the configuration file. Defaults to ‘./config.json’.
Platform-p , —platform Only build a specific platform. If not supplied, builds all platform found in the configuration file.
Silent-s, —silentSilence all logging, except for fatal errors.
Verbose-v, —verboseEnable verbose logging for reference errors, token collisions and filtered tokens with outputReferences.
No Warnings-n, —no-warnDisable warnings from being logged. Still logs success logs and fatal errors.

clean

Removes files and folders generated by a previously run ‘build’ command. Usage:

Terminal window
style-dictionary clean [options]

Options:

NameUsageDescription
Configuration Path-c , —config Set the path to the configuration file. Defaults to ‘./config.json’.
Platform-p , —platform Only clean a specific platform. If not supplied, cleans all platform found in the configuration file.
Silent-s, —silentSilence all logging, except for fatal errors.
Verbose-v, —verboseEnable verbose logging for reference errors, token collisions and filtered tokens with outputReferences.
No Warnings-n, —no-warnDisable warnings from being logged. Still logs success logs and fatal errors.

init

Generates a starter style dictionary, based on the supplied example type. Usage:

Terminal window
style-dictionary init <example-type>

Where example-type is one of:

  • basic
  • complete

version

To see what version of Style Dictionary you have, run this command:

Terminal window
style-dictionary --version