-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
CLI: Add index command / API #30071
base: next
Are you sure you want to change the base?
CLI: Add index command / API #30071
Conversation
View your CI Pipeline Execution ↗ for commit 7d99f49.
☁️ Nx Cloud last updated this comment at |
export const buildIndexStandalone = async (options: BuildIndexOptions) => { | ||
const index = await buildIndex(options); | ||
console.log(`Writing index to ${options.outputFile}`); | ||
await writeFile(options.outputFile, JSON.stringify(index, null, 2)); | ||
}; |
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.
Should this get added to standalone.ts
also? I'm not quite sure what's up with that API.
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.
12 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings | Greptile
import { findPackage } from 'fd-package-json'; | ||
import invariant from 'tiny-invariant'; | ||
|
||
export const buildIndex = async (cliOptions: any) => { |
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.
style: cliOptions should be properly typed rather than using 'any' to ensure type safety
configDir: cliOptions.configDir || './.storybook', | ||
outputFile: cliOptions.outputFile || './index.json', |
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.
logic: paths should use path.join() or path.resolve() to handle cross-platform path separators correctly
outputDir: 'SBCONFIG_OUTPUT_DIR', | ||
configDir: 'SBCONFIG_CONFIG_DIR', |
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.
logic: outputDir env variable is used but not relevant for index command which uses outputFile instead
outputDir: 'SBCONFIG_OUTPUT_DIR', | |
configDir: 'SBCONFIG_CONFIG_DIR', | |
configDir: 'SBCONFIG_CONFIG_DIR', |
console.log(`Writing index to ${options.outputFile}`); | ||
await writeFile(options.outputFile, JSON.stringify(index)); |
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.
style: Use logger.info instead of console.log to maintain consistent logging throughout the codebase
await index({ | ||
...options, | ||
packageJson: pkg, | ||
test: !!options.test || process.env.SB_TESTBUILD === 'true', |
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.
logic: test option is used but not defined in command options (unlike build command)
|
||
import { StoryIndexGenerator } from './utils/StoryIndexGenerator'; | ||
|
||
type BuildIndexOptions = CLIOptions & LoadOptions & BuilderOptions & { outputFile: string }; |
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.
style: BuildIndexOptions type should be exported since it's used by public API functions
type BuildIndexOptions = CLIOptions & LoadOptions & BuilderOptions & { outputFile: string }; | |
export type BuildIndexOptions = CLIOptions & LoadOptions & BuilderOptions & { outputFile: string }; |
@@ -1,6 +1,7 @@ | |||
import { dirname } from 'node:path'; | |||
|
|||
import { buildDevStandalone } from './build-dev'; | |||
import { buildIndexStandalone } from './build-index'; | |||
import { buildStaticStandalone } from './build-static'; | |||
|
|||
async function build(options: any = {}, frameworkOptions: any = {}) { |
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.
style: Consider adding TypeScript types for options and frameworkOptions parameters instead of 'any'
| Option | Description | | ||
| --------------------------------- | ----------------------------------------------------- | | ||
| `-o`, `--output-file <file-name>` | JSON file to output index | | ||
| `-c`, `--config-dir <dir-name>` | Directory where to load Storybook configurations from | | ||
| `--quiet` | Suppress verbose build output | | ||
| `--loglevel <level>` | Control level of logging during build | |
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.
style: Should include --disable-telemetry
and --enable-crash-reports
options for consistency with other commands
| Option | Description | | |
| --------------------------------- | ----------------------------------------------------- | | |
| `-o`, `--output-file <file-name>` | JSON file to output index | | |
| `-c`, `--config-dir <dir-name>` | Directory where to load Storybook configurations from | | |
| `--quiet` | Suppress verbose build output | | |
| `--loglevel <level>` | Control level of logging during build | | |
| Option | Description | | |
| --------------------------------- | ----------------------------------------------------- | | |
| `-o`, `--output-file <file-name>` | JSON file to output index | | |
| `-c`, `--config-dir <dir-name>` | Directory where to load Storybook configurations from | | |
| `--quiet` | Suppress verbose build output | | |
| `--loglevel <level>` | Control level of logging during build | | |
| `--disable-telemetry` | Disables Storybook's telemetry | | |
| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry | |
Closes #
What I did
storybook index
command that createsindex.json
without building the storybookbuildIndex
API to do the same thing as a Node APITesting
The changes in this PR are covered in the following automated tests:
Manual testing
Run
storybook index
on a project and verify thatindex.json
matchesstorybook build
'sstorybook-static/index.json
Documentation
MIGRATION.MD
🦋 Canary release
This pull request has been released as version
0.0.0-pr-30071-sha-26d114f9
. Try it out in a new sandbox by runningnpx [email protected] sandbox
or in an existing project withnpx [email protected] upgrade
.More information
0.0.0-pr-30071-sha-26d114f9
shilman/build-index
26d114f9
1740321218
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=30071
Greptile Summary
Introduces a new
storybook index
command andbuildIndex
API that generates anindex.json
file containing story metadata without building the full Storybook, improving build efficiency for specific use cases.code/core/src/cli/buildIndex.ts
implementing core functionality to generate index without full buildcode/core/src/core-server/build-index.ts
handling configuration loading, presets, and story index generationcode/lib/cli/src/proxy.ts
to include 'index' command in CLI command handlingcode/core/src/core-server/build-index.test.ts
verifying index generationcode/core/src/telemetry/types.ts
to track new 'index' command usage