story2sketch icon indicating copy to clipboard operation
story2sketch copied to clipboard

--stories argument is never parsed

Open cameronmurphy opened this issue 6 years ago • 2 comments

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.

cameronmurphy avatar Jan 22 '19 00:01 cameronmurphy

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.

chrisvxd avatar Jan 25 '19 16:01 chrisvxd

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.

cameronmurphy avatar Jan 30 '19 00:01 cameronmurphy