Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Storybook build args #4455

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,13 +52,24 @@ 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 = ({
// eslint-disable-next-line no-unused-vars
open,
port,
build,
Expand All @@ -77,21 +92,56 @@ 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}`,
thedavidprice marked this conversation as resolved.
Show resolved Hide resolved
`--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`,
thedavidprice marked this conversation as resolved.
Show resolved Hide resolved
].filter(Boolean),
thedavidprice marked this conversation as resolved.
Show resolved Hide resolved
{
stdio: 'inherit',
shell: true,
cwd,
}
)
}
)
} catch (e) {
console.log(c.error(e.message))
errorTelemetry(process.argv, e.message)
process.exit(1)
}
}