cobalt-ui icon indicating copy to clipboard operation
cobalt-ui copied to clipboard

Add JSON output to plugin-js

Open gynekolog opened this issue 1 year ago • 1 comments

The doc says:

pluginJS({
      output: {
        js: "index.js",
        ts: "index.d.ts",
        json: false, // set to a filename to generate JSON
      },
    }),

but the current @terrazzo/plugin-js (0.1.0) expects different configuration:

 js({
      js: "index.js",
      // json: "tokens.json",
    }),

image

Is the doc or the plugin out of date? I can create a pull request with edits.

gynekolog avatar Nov 12 '24 10:11 gynekolog

Thanks for flagging! A bit of both.

ts - The new version dropped the ts option. It will just output .d.ts regardless of settings. There’s no reason you wouldn’t want this; it just improves interop invisibly (and if you don’t use TS, it’s just ignored). Further, there’s no reason you would ever name .d.ts differently than .js—that would just break TypeScript. So the API is just improved to be simpler here.

json - This is undone work I forgot about! We want to output a .json output that roughly matches the default JS output. Some questions that I’m not sure about, that the implementer can weigh in on:

  • Since the js output exports a flat object of IDs → token values (with modes), should JSON do the same?
  • js just discards a lot of the metadata from tokens (like $description). I got requests from people asking to not generate this, since they never used it. Is there any additional metadata we would want in the js output?
    • If we include any metadata in js, would JSON need any of that? (should it be a reserved namespace at the top?)

I’ve updated the issue name to better reflect the scope of work to be done. Would love a PR, whether that’s from you or anyone else reading this!

drwpow avatar Nov 13 '24 01:11 drwpow