design-tokens
is a command line tool to translate design tokens into Swift source code.
This package follows the Design Tokens Format specifications by the Design Tokens Community Group for the translation.
To compile the binary, run the following command in the directory of the cloned repository:
swift build -c release design-tokens --show-bin-path
The command will output the path of the built binary.
Alternatively, you can run the tool directly without exporting a binary.
swift run -c release design-tokens
The tool must be configured via a configuration manifest JSON file to run, and generate an output.
The command line tool provides two commands to initialize a configuration manifest, and to generate output for the specified design token files.
Scaffolds a configuration manifest file with default parameters. To scaffold a configuration, the path to the input design token file is required.
design-tokens init -i design-tokens.json
Generates the output as configured in the configuration manifest.
design-tokens generate
The command line tool generates source code as the resulting output of the design tokens translation. The format of the output can be customized on a per-token basis.
{
"input": "design-tokens.json",
"colors": {
"output": "Output/Colors/"
},
"dimensions": {
"output": "Output/Dimensions/"
}
}
Using the manifest above, the generate
command will generate SwiftUI
, and UIKit
source code for the color tokens in the Output/Colors/
directory. It will also generate source code (default) for the dimension
tokens in the Output/Dimensions/
directory.