Skip to content

Commit

Permalink
Start storybooks on predefined ports by default (#29954)
Browse files Browse the repository at this point in the history
* Start storybooks on predefined ports by default

* lints
  • Loading branch information
Dima Voytenko committed Aug 25, 2020
1 parent fb8075c commit 8b58b60
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions build-system/tasks/storybook/index.js
Expand Up @@ -19,17 +19,21 @@ const argv = require('minimist')(process.argv.slice(2));
const {exec} = require('../../common/exec');
const {installPackages} = require('../../common/utils');

let storybookArgs = '--quiet';
if (argv.port) {
storybookArgs += ` -p ${argv.port}`;
}
const DEFAULT_PORTS = {
'amp': 9001,
'preact': 9002,
};

function runStorybook(mode) {
// install storybook-specific modules
installPackages(__dirname);

const port = argv.port || DEFAULT_PORTS[mode];

exec(
`./node_modules/.bin/start-storybook -c ./${mode}-env ${storybookArgs}`,
`./node_modules/.bin/start-storybook --quiet -c ./${mode}-env -p ${port} ${
argv.ci ? '--ci' : ''
}`,
{
'stdio': [null, process.stdout, process.stderr],
cwd: __dirname,
Expand All @@ -43,14 +47,14 @@ function runStorybook(mode) {
* for AMP components (HTML Environment)
*/
function storybookAmp() {
runStorybook('amp' /** mode */);
runStorybook('amp' /* mode */);
}

/**
* Simple wrapper around the storybook start script.
*/
function storybookPreact() {
runStorybook('preact' /** mode */);
runStorybook('preact' /* mode */);
}

module.exports = {
Expand All @@ -65,4 +69,5 @@ storybookAmp.description =

storybookPreact.flags = storybookAmp.flags = {
'port': ' Change the port that the storybook dashboard is served from',
'ci': " CI mode (skip interactive prompts, don't open browser)",
};

0 comments on commit 8b58b60

Please sign in to comment.