-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
CLI: Modernize Storybook CLI with new init workflow, Clack UI, and Generator System #32717
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
Changes from all commits
c14bdd4
6f00339
f500eaf
a72ee5b
650fbfd
9bfb67b
a58ac65
69a49be
fc738f3
6ae03af
98a6d87
742898d
dc4970b
f542c30
ed93646
55ab695
0636bca
a94202e
9b61d16
8803ec2
db397d5
fab118c
c43c7d1
8f4adc9
494a348
f2e303f
22e819f
c30500d
82491a8
950ca75
fc4c3dd
b8954bb
d0ac4e6
48c1634
cc9ec9c
650ba10
e14a93b
e9b2e09
e4f9db7
9e0a69a
a2e2697
b0f26de
a289692
74aa16a
c1fd37a
f8641b6
8964063
7822623
a85f440
e3d2f2c
be57f8f
96baa71
44105d3
6b32df7
be6d33a
be0e21b
0dd4c12
bbc2123
9ff8653
7775199
a08cb94
04f6bcd
6aae3d9
1f13f05
48b24cc
efedfe9
14becd3
07dd5d4
d08caed
12ed766
03a3473
970ec6d
ec0855b
eef0799
16b7aab
aa29e7f
34f9bce
051edf1
2915632
d5071f5
6ed2906
e379604
22ae068
056f22b
d8c2ffd
ca75222
2fda23b
423a1a9
eb521b3
541b4df
926fd23
31bee8b
264865b
62527cd
d201104
28b96f1
04f7a99
eb1da8e
2497fc6
4d8782a
31bda49
bada431
a9da81c
71c8766
d1f6bed
a1366f7
cd441a7
248b61a
82cd1be
cabdff3
6321d48
5f21e96
9f8743a
2c7ac43
b5e87fc
871c615
bbc59ea
a960afd
061781a
78236e1
3ffa86e
6e1bb50
e54f891
897cf7a
ec6de36
64fbedc
9719b1d
bf72e84
b56df2c
993b2dd
eee9dbe
9ba0234
1942e52
8384d92
cd83b83
1e614ac
d54b4b7
e550bfe
8ccc6e1
0df27a4
54fd6e5
879348e
6df4537
f1ac524
a77ee36
79093a6
a90e13b
c74f361
b3d776e
9d927b5
4fe5728
9d044ba
67d3622
45db1a6
4a3c63a
ecd6ecb
f09bcd2
b9f4440
38a925e
1441e05
a6955af
02f2ddb
34d3f5e
edcf22f
c4ce21c
37524ac
aaad3f1
b7fece0
8e2937d
baa5ad6
116cf23
a84ea41
b9eb956
f9221a8
ae93da3
80a78e7
eb59ba8
1be5aa8
1ab6043
e8977ce
5667637
a2d573b
5df8b2f
11c1b66
5771247
f712f28
f3cf116
629e0a9
f2862e2
8e2cc64
9e9d891
edc314e
87bd414
da8535c
2fb3ded
b764abe
abdfb4d
922b4f3
669c2a9
76d2b20
f2fb106
b13e056
881a637
c0d0a5e
5ff022b
ad5b4ad
788ad55
9ded6e4
659c72d
58e0e7e
d980a39
47ba298
f340a68
aed6511
5ad2c34
b8c5e10
f201f00
fbdca15
1e131d4
3377ff9
32ecbaa
aa48b31
26d7272
c24667d
c0982c8
1aa4ae3
2129a2f
8ebf943
59d7b8e
0abdc8c
e618441
0cc0297
5fb40e9
05b3522
ac3cb17
ede3808
d239246
82c9739
eb452b4
b0a5168
72a9017
d484f05
23c335a
12e7055
9349f71
7a16d82
4b955ff
d9ca7b4
07f890c
b01def1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,29 @@ | ||
| // eslint-disable-next-line depend/ban-dependencies | ||
| import { execa } from 'execa'; | ||
| import { JsPackageManagerFactory } from 'storybook/internal/common'; | ||
|
|
||
| import type { PostinstallOptions } from '../../../lib/cli-storybook/src/add'; | ||
|
|
||
| const $ = execa({ | ||
| preferLocal: true, | ||
| stdio: 'inherit', | ||
| // we stream the stderr to the console | ||
| reject: false, | ||
| }); | ||
|
|
||
| export default async function postinstall(options: PostinstallOptions) { | ||
| const command = ['storybook', 'automigrate', 'addon-a11y-addon-test']; | ||
| const args = ['storybook', 'automigrate', 'addon-a11y-addon-test']; | ||
|
|
||
| command.push('--loglevel', 'silent'); | ||
| command.push('--skip-doctor'); | ||
| args.push('--loglevel', 'silent'); | ||
| args.push('--skip-doctor'); | ||
|
|
||
| if (options.yes) { | ||
| command.push('--yes'); | ||
| args.push('--yes'); | ||
| } | ||
|
|
||
| if (options.packageManager) { | ||
| command.push('--package-manager', options.packageManager); | ||
| args.push('--package-manager', options.packageManager); | ||
| } | ||
|
|
||
| if (options.configDir) { | ||
| command.push('--config-dir', `"${options.configDir}"`); | ||
| args.push('--config-dir', options.configDir); | ||
| } | ||
|
|
||
| await $`${command.join(' ')}`; | ||
| const jsPackageManager = JsPackageManagerFactory.getPackageManager({ | ||
| force: options.packageManager, | ||
| configDir: options.configDir, | ||
| }); | ||
|
|
||
| await jsPackageManager.runPackageCommand({ args }); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||
| import { spawn } from 'child_process'; | ||||||||||||||||||
| import { spawnSync } from 'child_process'; | ||||||||||||||||||
|
|
||||||||||||||||||
| const PACKAGE_MANAGER_TO_COMMAND = { | ||||||||||||||||||
| npm: 'npx', | ||||||||||||||||||
|
|
@@ -12,11 +12,11 @@ const selectPackageManagerCommand = (packageManager: string) => | |||||||||||||||||
| PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND]; | ||||||||||||||||||
|
|
||||||||||||||||||
| export default async function postinstall({ packageManager = 'npm' }) { | ||||||||||||||||||
| const command = selectPackageManagerCommand(packageManager); | ||||||||||||||||||
| const commandString = selectPackageManagerCommand(packageManager); | ||||||||||||||||||
| const [command, ...commandArgs] = commandString.split(' '); | ||||||||||||||||||
|
Comment on lines
+15
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Handle undefined commandString to prevent runtime crash. If an unrecognized Apply this diff to add defensive handling: const commandString = selectPackageManagerCommand(packageManager);
+ if (!commandString) {
+ console.error(`Unsupported package manager: ${packageManager}`);
+ return;
+ }
const [command, ...commandArgs] = commandString.split(' ');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| await spawn(`${command} @storybook/auto-config themes`, { | ||||||||||||||||||
| spawnSync(command, [...commandArgs, '@storybook/auto-config', 'themes'], { | ||||||||||||||||||
| stdio: 'inherit', | ||||||||||||||||||
| cwd: process.cwd(), | ||||||||||||||||||
| shell: true, | ||||||||||||||||||
| }); | ||||||||||||||||||
valentinpalkovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| import { logger } from 'storybook/internal/node-logger'; | ||
|
|
||
| import picocolors from 'picocolors'; | ||
|
|
||
| import { ADDON_ID } from './constants'; | ||
|
|
||
| export const log = (message: any) => { | ||
| console.log(`${picocolors.magenta(ADDON_ID)}: ${message.toString().trim()}`); | ||
| logger.log( | ||
| `${picocolors.magenta(ADDON_ID)}: ${message | ||
| .toString() | ||
| // Counteracts the default logging behavior of the clack prompt library | ||
| .replaceAll(/(│\n|│ )/g, '') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment to explain what this does. |
||
| .trim()}` | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove unnecessary
asynckeyword.The function body is entirely synchronous (
spawnSyncdoesn't return a Promise), so theasyncdeclaration is misleading.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents