chrisvxd / story2sketch

Convert Storybook into Sketch symbols 💎
Other
402 stars 32 forks source link

--stories argument is never parsed #61

Open cameronmurphy opened 5 years ago

cameronmurphy commented 5 years ago

To pass stories via the command line, the --stories argument needs to be parsed. It is simply merged into the config as a string here: https://github.com/chrisvxd/story2sketch/blob/master/src/server/index.js#L61

For it to work I had to add:

  if (newConfig.stories && newConfig.stories !== 'all') {
    newConfig.stories = JSON.parse(newConfig.stories);
  }

to tidyConfig().

This enables story2sketch --stories '[{"kind":"Buttons/Button","stories":[{"name":"Button"}]}]' to work.

chrisvxd commented 5 years ago

Hey @cameronmurphy. Thanks for raising this.

So I deliberately left the JSON parsing out as it seemed clunky to add JSON to the CLI, but then proceeded to do a poor job documenting it.

In future, I've considered adding a simpler CLI syntax, something like: story2sketch --stories Buttons/Primary,Buttons/Secondary.

So options are:

  1. Clarify docs with existing behaviour
  2. Add JSON.parse since it doesn't hurt
  3. Change to new CLI-only --stories syntax

If you have a preference, please feel free to open a PR. Otherwise, I'll address when time allows.

cameronmurphy commented 5 years ago

Agreed JSON on the command line is clunky. We're exporting stories split into files by grouping. If we export all 400 odd components into the same asketch.json, Sketch likes to crash. So an alternative would be a by-group option in addition to all as possible values for the --stories argument.

At the moment the way we're achieving this is by generating a story2sketch.config.js file, running story2sketch, removing the config file, writing the config file, running story2sketch etc.