Skip to content

A tool to translate Design Tokens into Swift source code.

License

Notifications You must be signed in to change notification settings

gaetanomatonti/swift-design-tokens

Repository files navigation

Codemagic build status

What's design-tokens?

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.

Install

Compile sources

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

Configuration

The tool must be configured via a configuration manifest JSON file to run, and generate an output.

Usage

The command line tool provides two commands to initialize a configuration manifest, and to generate output for the specified design token files.

init

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

generate

Generates the output as configured in the configuration manifest.

design-tokens generate

Output

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.

Example

{
  "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.