Using CLI

The Tokun command line interface (CLI) provides useful functionality with fewer configurations in an executable format.

Installation

To use CLI you can install it globally:

 

Or have it as a dev dependency in your project:

 

Or use it directly via a package runner:

 

Commands

The CLI provides the following commands:

  • build — Build design tokens to a different format. This builder is simplified, to use more advencent option please create a custom script.
  • validate — Validate design tokens against the DTCG format.

build

Build design tokens to a different format. This builder is simplified, to use more advencent option please create a custom script.

tokun build

If options are not provided, then the command will try to find a config.json file in the root.

Options:

NameUsageDescription
Configuration path-c, --config <config>The path to the config file.
Input path-i, --input <input>Path to a single input token file.
Output path-o, --output <output>The output file to write.
Loader-l, --loader <loader>Loader for input/output mode. Defaults to first registered loader.
Format-f, --format <format>Format for input/output mode. If omitted, it is inferred from output extension (.css, .scss, .detailed.json, .json).
Silent-s, --silentSilence non-fatal logs.
Verbose-v, --verboseEnable verbose logs (default).
No warnings-n, --no-warnDisable warning logs.

Examples:

tokun build --input tokens.json --output dist/tokens.css
tokun build --input tokens.json --output dist/tokens.out --format css --loader dtcg-json
tokun build --input tokens.json --output dist/tokens.css --silent
tokun build --input tokens.json --output dist/tokens.css --no-warn

Config file

You can create configuration file which you can use with CLI build command.

{
  "scripts": {
    "build": "tokun build -c config.json"
  }
}

And the simplest configuration may look like this:

export default {
  data: ["templates/simple/simple.tokens.json"],
  options: {
    loader: "dtcg-json",
    platforms: [
      {
        name: "css",
        format: "css",
        transforms: ["kebab-case", "css-transforms"],
        outputs: [
          {
            name: "dist/simple/vars.css",
          },
        ],
        config: { outputReferences: true },
      },
    ],
  },
};

For more details, read Config API.

validate

Validate design tokens against the DTCG format.

tokun validate <inputs...>

Arguments:

NameUsageDescription
Inputs<inputs...>The input files to validate. This can be a glob pattern. See tinyglobby for more information.

Options:

NameUsageDescription
Silent-s, --silentSilence non-fatal logs.
Verbose-v, --verboseEnable verbose logs (default).
No warnings-n, --no-warnDisable warning logs.