Skip to content

Commit

Permalink
Fix Storybook build args (#4455)
Browse files Browse the repository at this point in the history
* open arg default set to false

* small indentation correction

* separate logic for 3 cases

* small fix: param deleted in build

* PR comments resolved

* fixing quote marks

* no open argument included

Co-authored-by: David Price <thedavid@thedavidprice.com>
  • Loading branch information
josemasar and thedavidprice committed Feb 18, 2022
1 parent 932d198 commit d9284aa
Showing 1 changed file with 68 additions and 18 deletions.
86 changes: 68 additions & 18 deletions packages/cli/src/commands/storybook.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import path from 'path'

import execa from 'execa'
import terminalLink from 'terminal-link'

import { getPaths } from '@redwoodjs/internal'
import { errorTelemetry } from '@redwoodjs/telemetry'

import c from '../lib/colors'

export const command = 'storybook'
export const aliases = ['sb']
export const description =
'Launch Storybook: An isolated component development environment'
'Launch Storybook: a tool for building UI components and pages in isolation'

export const builder = (yargs) => {
yargs
Expand Down Expand Up @@ -48,10 +52,20 @@ export const builder = (yargs) => {
throw new Error('Can not provide both "--build" and "--smoke-test"')
}
if (argv.build && argv.open) {
throw new Error('Can not provide both "--build" or "--open"')
console.warn(
c.warning(
'Warning: --open option has no effect when running Storybook build'
)
)
}
return true
})
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference',
'https://redwoodjs.com/reference/command-line-interface#storybook'
)}`
)
}

export const handler = ({
Expand All @@ -77,21 +91,57 @@ export const handler = ({
require.resolve('@redwoodjs/testing/config/storybook/main.js')
)

execa(
`yarn ${build ? 'build' : 'start'}-storybook`,
[
`--config-dir "${storybookConfig}"`,
!build && `--port ${port}`,
!build && '--no-version-updates',
!managerCache && '--no-manager-cache',
build && `--output-dir "${buildDirectory}"`,
!open && !smokeTest && `--ci`,
smokeTest && `--ci --smoke-test`,
].filter(Boolean),
{
stdio: 'inherit',
shell: true,
cwd,
try {
if (build) {
execa(
`yarn build-storybook`,
[
`--config-dir "${storybookConfig}"`,
`--output-dir "${buildDirectory}"`,
!managerCache && `--no-manager-cache`,
].filter(Boolean),
{
stdio: 'inherit',
shell: true,
cwd,
}
)
} else if (smokeTest) {
execa(
`yarn start-storybook`,
[
`--config-dir "${storybookConfig}"`,
`--port ${port}`,
`--smoke-test`,
`--ci`,
`--no-version-updates`,
].filter(Boolean),
{
stdio: 'inherit',
shell: true,
cwd,
}
)
} else {
execa(
`yarn start-storybook`,
[
`--config-dir "${storybookConfig}"`,
`--port ${port}`,
!managerCache && `--no-manager-cache`,
`--no-version-updates`,
!open && `--no-open`,
].filter(Boolean),
{
stdio: 'inherit',
shell: true,
cwd,
}
)
}
)
} catch (e) {
console.log(c.error(e.message))
errorTelemetry(process.argv, e.message)
process.exit(1)
}
}

0 comments on commit d9284aa

Please sign in to comment.