amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.87k stars 543 forks source link

Misleading output when using `json` format for output #887

Open booc0mtaco opened 1 year ago

booc0mtaco commented 1 year ago

The documentation lists the format for json to have the following structure:

{
  "color": {
    "base": {
       "red": {
         "value": "#ff0000"
       }
    }
  }
}

The code uses the tokens without applying any transforms or omissions on .tokens. So it would seem this formatter would output the same as the input style dictionary.

However, this will result in output including all the additional metadata, which is different from what the documentation would suggest.

{
  "color": {
    "base": {
       "red": {
          "value": "red",
          "filePath": "path/to/input.json",
          "isSource": true,
          "original": {
            "value": "red"
          },
          "name": "ColorBaseRed",
          "attributes": {
            "category": "color",
            "type": "base",
            "item": "red",
          },
          "path": [
            "color",
            "base",
            "red",
          ]
        }
    }
}

Formatter in question

https://github.com/amzn/style-dictionary/blob/main/lib/common/formats.js#L1052-L1072

/**
   * Creates a JSON file of the style dictionary.
   *
   * @memberof Formats
   * @kind member
   * @example
   * ```json
   * {
   *   "color": {
   *     "base": {
   *        "red": {
   *          "value": "#ff0000"
   *        }
   *     }
   *   }
   * }
   * ```
   */
  'json': function({dictionary}) {
    return JSON.stringify(dictionary.tokens, null, 2);
  },

Either the documentation should be updated to reflect what actually gets output, OR the formatter should be updated to reflect the actual output that gets generated. Not sure which one is intended šŸ¤”.

booc0mtaco commented 1 year ago

@dbanksdesign I saw some recent activity from you on this repo. šŸ‘‹šŸ½ I am happy to submit a PR if I can find out whether the documentation or the formatter itself needs updating

booc0mtaco commented 1 year ago

bump?

doozMen commented 1 year ago

please do update the docs and not the output. I rely on that output to be as is.