0

I have a storybook start script which I want to run for some specific folder:

"storybook": "start-storybook -p 6006 -s ./src" 

This loads all stories from src folder. As the amount of stories becomes larger, I want to run stories only from some of subfolders:

start-storybook -p 6006 -s ./src/components/CommonComponents start-storybook -p 6006 -s ./src/components/DashboardComponents 

How can I format argument value dynamically in order to start storybook like this below?

$ yarn storybook CommonComponents 

And it would turn into:

start-storybook -p 6006 -s ./src/components/CommonComponents 
2
  • Does this answer your question? Pass command line args to npm scripts in package.json Commented Mar 17, 2021 at 12:23
  • On *nix consider utilizing a shell function. For example, define your script in package,json as "storybook": "func() { start-storybook -p 6006 -s \"./src/${1}\"; }; func", then run the following command: yarn run storybook components/CommonComponents. For a cross-plaform solution you'll need to consider writing a node.js script which is also described in my answer here. Commented Mar 17, 2021 at 12:26

1 Answer 1

1

storybook task could be a script, and then inside the script you parse the arguments, and call start-storybook

  1. Create a task in package.json (e.q run-storybook) and set it to execute the custom script:
"run-storybook": yarn ./path/to/script.js 
#!/bin/env node // script.js const { spawn } = require('child_process') const args = process.argv.slice(2) const port = args[1] const component = args[3] const path = `./src/components/${component}` spawn('yarn', ['start-storybook', '-p', port, '-s', path], { stdio: 'inherit', shell: true }) 

Then you can call: yarn run-storybook -p 600 -s yourcomponent

Note: make sure the script is executable: chmod +x /path/to/script.js.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.