Primitree

Export Variables

Create a variables.json file for the Primitree build.

Primitree accepts a Variables REST API response, a bare meta object, or a plugin export with variables and collections.

Primitree export plugin

During local development, load the Primitree export plugin from this repository:

  1. Build the plugin with pnpm --filter primitree-plugin build
  2. In Figma, choose Plugins → Development → Import plugin from manifest
  3. Select apps/figma-plugin/dist/manifest.json
  4. Run Primitree export and download variables.json

The plugin calls getLocalVariableCollectionsAsync() and getLocalVariablesAsync() in the open file. The CLI reads its output as a REST local variables response.

Other plugin exports

Primitree accepts these layouts:

  • { meta: { variables, variableCollections } }
  • { variables, variableCollections }
  • { variables: [...], collections: [...] }

The normalizer accepts record maps or arrays for variables and collections. Published variables responses do not contain mode values and cannot feed the build.

Variables REST API

Figma limits the Variables REST API to Enterprise organizations. A local variables request needs file_variables:read and access to the file.

export FIGMA_TOKEN=figd_...
export FIGMA_FILE_KEY=AbCdEf...

primitree export --out variables.json

Run a check before building:

primitree check variables.json

Keep exports in version control

Commit variables.json when the repository needs to compare stable Figma IDs, names, types, and per-mode values across changes.

See Semantic diffing for how matching works.