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:

npm install -g tokun

Or have it as a dev dependency in your project:

npm install -D tokun

Or use it directly via npx:

npx tokun

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 search for config.json file in the root.

Options:

NameUsageDescription
Configuration path-c, --config <config>The path to the config file.
Input path-i, --input <input>The input file. This can be a glob pattern. See tinyglobby for more information.
Output path-o, --output <output>The output file to write.

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/basic/basic.tokens.json"],
  options: {
    loader: "dtcg-json",
    platforms: [
      {
        name: "css",
        format: "css",
        transforms: ["kebab-case", "css-transforms"],
        outputs: [
          {
            name: "dist/basic/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.