tokens-bruecke / figma-plugin

TokensBrücke is a Figma plugin that converts Figma variables into design-tokens JSON.
MIT License
39 stars 7 forks source link

No value key in token schema #3

Closed cailborg closed 10 months ago

cailborg commented 10 months ago

When i run the plugin the schema generates fine - but there is no "value" key for the color tokens

{
  "sonic": {
    "color": {
      "background": {
        "button": {
          "primary": {
            "default": {
              "type": "color",
              "description": "",
              "scopes": [
                "SHAPE_FILL",
                "FRAME_FILL"
              ],
              "extensions": {
                "variableId": "VariableID:1:3",
                "aliasPath": "{sonic.color.background.button.primary.default}"
              }
            },
            "hover": {
              "type": "color",
              "description": "",
              "scopes": [
                "SHAPE_FILL",
                "FRAME_FILL"
              ],
              "extensions": {
                "variableId": "VariableID:14:46",
                "aliasPath": "{sonic.color.background.button.primary.hover}"
              }
            }
        }
   }

Other tokens (e.g space) work fine

"space": {
      "element": {
        "large": {
          "value": "12px",
          "type": "dimension",
          "description": "",
          "scopes": [
            "GAP"
          ],
          "extensions": {
            "variableId": "VariableID:1:4",
            "aliasPath": "{sonic.space.element.large}"
          }
        },
PavelLaptev commented 10 months ago

@cailborg looks like it's a "nesting" issue. I'll try to reproduce this schema on my side

PavelLaptev commented 10 months ago

@cailborg that's odd. Can't reproduce this bug. I recreated the same structure (see the image below). These missing color values are alias values?

image

If it's okay for you, we can plan a call and check this issue together. Feel free to write me to pavellaptev.figma@gmail.com

cailborg commented 10 months ago

One difference is I don't have a "value" column in my variables table - i'm setting up modes for light and dark

Screenshot 2023-08-17 at 9 51 15 am
cailborg commented 10 months ago

Oh and maybe the fact that they are aliased from another set of variables?

PavelLaptev commented 10 months ago

Hm… renaming the Value title and add alias variables didn't show the bug.

image
PavelLaptev commented 10 months ago

But might be there is a bug in the method how I check if the value is alias.

Can you please test this version? (see attachment)

plugin-test-version.zip

This is how you can add a custom plugin in Figma. Go to plugins » development » click on the plus button » add from manifest

image
cailborg commented 10 months ago

Development version didn't change any outputs - are you using resolveForConsumer in the Figma API to resolve aliases? https://www.figma.com/plugin-docs/api/Variable#resolveforconsumer

cailborg commented 10 months ago

I have discovered the source of the bug - aliases only work where base is a new collection in the same file. I was originally aliasing tokens from a variable collection in a different file (as I don't want people applying the base tokens to designs)

Screenshot 2023-08-17 at 12 35 32 pm
PavelLaptev commented 10 months ago

@cailborg thanks for investigating this. Will try to fix this today

PavelLaptev commented 10 months ago

@cailborg I published a new plugin version 1.2.0 Can you try it out?

The plugin will generate an alias name anyway, but it will be a path to the variable as if it was in the current file.

{
  "button": {
    "background": {
      "type": "color",
      "value": "{colors.light.primary.10}"
    }
  }
}

The plugin wouldn't include the variable into the generated JSON in order to avoid duplicates or conflicts with JSON files you can generate from another Figma files.

So you will need to merge the file with the base variables with another where you use them. Otherwise tools like Style Dictionary wouldn't be able to resolve the aliases.

cailborg commented 10 months ago

Working perfectly, thanks!