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:
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.
In your package.json
file you can add an NPM script that runs Style Dictionary:
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:
build
Builds a style dictionary package from the current directory. Usage:
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:
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:
Where example-type is one of:
basic
complete
version
To see what version of Style Dictionary you have, run this command: