forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storybook.js
90 lines (82 loc) · 2.23 KB
/
storybook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import path from 'path'
import execa from 'execa'
import { getPaths } from '@redwoodjs/internal'
export const command = 'storybook'
export const aliases = ['sb']
export const description =
'Launch Storybook: An isolated component development environment'
export const builder = (yargs) => {
yargs
.option('open', {
describe: 'Open storybooks in your browser on start',
type: 'boolean',
default: true,
})
.option('build', {
describe: 'Build Storybook',
type: 'boolean',
default: false,
})
.option('port', {
describe: 'Which port to run storybooks on',
type: 'integer',
default: 7910,
})
.option('build-directory', {
describe: 'Directory in web/ to store static files',
type: 'string',
default: 'public/storybook',
})
.option('manager-cache', {
describe:
"Cache the manager UI. Disable this when you're making changes to `storybook.manager.js`.",
type: 'boolean',
default: true,
})
.option('ci', {
describe:
"CI mode plus Smoke-test (skip prompts, don't open browser, exit after successful start)",
type: 'boolean',
default: false,
})
}
export const handler = ({
open,
port,
build,
buildDirectory,
managerCache,
ci,
}) => {
const cwd = getPaths().web.base
const staticAssetsFolder = path.join(getPaths().web.base, 'public')
// Create the `MockServiceWorker.js` file
// https://mswjs.io/docs/cli/init
execa(`yarn msw init "${staticAssetsFolder}" --no-save`, undefined, {
stdio: 'inherit',
shell: true,
cwd,
})
const storybookConfig = path.dirname(
require.resolve('@redwoodjs/testing/config/storybook/main.js')
)
execa(
`yarn ${build ? 'build' : 'start'}-storybook`,
[
`--config-dir "${storybookConfig}"`,
!build && `--port ${port}`,
!build && '--no-version-updates',
!build && `--static-dir "${staticAssetsFolder}"`,
!managerCache && '--no-manager-cache',
build &&
`--output-dir "${path.join(getPaths().web.base, buildDirectory)}"`,
!open && '--ci',
ci && '--ci --smoke-test --preview-url "ci"',
].filter(Boolean),
{
stdio: 'inherit',
shell: true,
cwd,
}
)
}