Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract variable rest api #29

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Conversation

origami-z
Copy link
Contributor

@origami-z origami-z commented Jan 10, 2024

Demonstrate the workflow to extract variables from Figma REST API, then use StyleDictionary to generate cross-platform style output (with some modification of data detailed below).

Below 2 env variables are needed for the code to run (in .env file)

  • FIGMA_FILE_ID, click the share button in Figma, get the id after /file/
  • FIGMA_ACCESS_TOKEN, see Figma doc to generate

The script (src/index.js) covers:

  1. Get data from REST API callFigmaAPI (requires FIGMA_FILE_ID and FIGMA_ACCESS_TOKEN present as env variables) or load from a local cached version loadLocalMockData
  2. updateApiResponse filters remote variables and appends "/default" to any variable name which also served as a nested group name (not supported by StyleDictionary mentioned here)
  3. writeTokensToFile writes tokens into tokens output folder, which is grouped by each folder and mode names like below
|- Collection 1
  |- Mode 1.json
  |- Mode 2.json
|- Collection 2
|- Collection 3
  1. buildUsingStyleDictionary uses style-dictionary-utils to parse token data using design tokens draft spec format and output end result, e.g. CSS variables and iOS Swift file.

Given tokens are grouped in folders (in step 3), common tokens can be consumed and referenced. e.g. If light and dark modes both reference a common color palette (defined in a different collection), both mode build pipelines can consume the same common source.

Previous experiment from Salt: jpmorganchase/salt-ds#58.

Additional notes

#### Style Dictionary

  • Couldn't find any documentation around the use of prefix in platform config, but it can be used to prefix DS name, e.g. "salt". See name/cti/kebab in code.
  • Default style dictionary attribute (attribute/cti) relies on token name location, likely we will need a different attribute system
  • Given "/default" is added to accommodate reference, we should play with a custom transform to remove -default
  • Any capital letter in the token name will be converted to a new part, e.g. Grey/600/40A will become var(--grey-600-40-a)

@origami-z origami-z requested a review from a team as a code owner January 10, 2024 09:45
@origami-z origami-z marked this pull request as draft January 10, 2024 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant