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:
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.
npm install --save-dev style-dictionary
In your package.json
file you can add an NPM script that runs Style Dictionary:
{ "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:
style-dictionary [command] [options]
build
Builds a style dictionary package from the current directory. Usage:
style-dictionary build [options]
Options:
Name | Usage | Description |
---|---|---|
Configuration Path | -c | Set the path to the configuration file. Defaults to ‘./config.json’. |
Platform | -p | Only build a specific platform. If not supplied, builds all platform found in the configuration file. |
Silent | -s, —silent | Silence all logging, except for fatal errors. |
Verbose | -v, —verbose | Enable verbose logging for reference errors, token collisions and filtered tokens with outputReferences. |
No Warnings | -n, —no-warn | Disable warnings from being logged. Still logs success logs and fatal errors. |
clean
Removes files and folders generated by a previously run ‘build’ command. Usage:
style-dictionary clean [options]
Options:
Name | Usage | Description |
---|---|---|
Configuration Path | -c | Set the path to the configuration file. Defaults to ‘./config.json’. |
Platform | -p | Only clean a specific platform. If not supplied, cleans all platform found in the configuration file. |
Silent | -s, —silent | Silence all logging, except for fatal errors. |
Verbose | -v, —verbose | Enable verbose logging for reference errors, token collisions and filtered tokens with outputReferences. |
No Warnings | -n, —no-warn | Disable warnings from being logged. Still logs success logs and fatal errors. |
init
Generates a starter style dictionary, based on the supplied example type. Usage:
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:
style-dictionary --version