Proof of concept fix: token generation for dashboard #317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: the existing build scripts don't generate any output for the dashboard tokens. #316
After some debugging, it appears that
omod
cannot resolve variables from different tokensets. Thedashboard
token sets exclusively refer to tokens in theorigin
set, and hence all their values end up empty.Fortunately, there's an official npm package from tokens-studio to transform these figma tokens: https://www.npmjs.com/package/token-transformer
Unfortunately, that package also doesn't work 100% how we would want.
Our existing build takes all tokenSets, and generate outputs for each of them. I tried this with
token-transformer
too.token-transformer
works slightly different though, and flattens the output. So if we want to have grouped outputs, we need to run it once per tokenset. And then to resolve all variables correctly, we need to:E.g. in order to build "dashboard/darkMode", we'd need to pass:
inputs: dashboard/darkMode,origin,base
excludes: origin,base
The output will be just the dashboard/darkMode values, with values resolved from any of the sets.
So my first attempt was this:
This means that for each tokenSet we can resolve variables from any other tokenSet.
Unfortunately, this is where I ran into issues: apparently, this doesn't quite work when there's overlap in naming between the tokensets. Specifically, since darkMode and lightMode share all the same keys, this would result in the
lightMode
file just being completely empty.So from here, I had 2 options:
lightMode
anddarkMode
.I managed to do the second. The data file has a "themes" section, which indicates which sets are needed for each theme, and which is the "target set". So we can use that.
The only caveat here is that this now doesn't include a standalone export for the "origin" set. Our current builds all include an "origin" set (with all the "reference only" values), but on this new build this will be gone. Now given that all of these are "reference only", I would assume they're not used anywhere in product, but I don't have enough context for this.
Lastly, the switch from omod -> token-transformer also has some smaller differences in output format:
#000000ff
we would now get#000000
. I don't know if this would break anything, advice needed.Summary
token-transformer
package such that we can properly resolve the references fordashboard/lightMode
anddashboard/darkMode
origin
export