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

Core: Built-in static stories.json support #14945

Merged
merged 16 commits into from
May 18, 2021
Merged

Core: Built-in static stories.json support #14945

merged 16 commits into from
May 18, 2021

Conversation

shilman
Copy link
Member

@shilman shilman commented May 15, 2021

Issue: N/A

What I did

  • Add @storybook/csf-tools for statically analyzing CSF files
  • Extract stories.json
    • in dev mode
    • in production mode
  • Add parameters.fileName

self-merging to unblock @tmeasday

Current limitations

Moved => #14966

What I need

Since lots of story metadata is NOT statically analyzable, we might need to redesign stories.json and/or composition to accommodate static results

How to test

Manual test cases in html-kitchen-sink (aka H) / react-ts (aka R) examples. Uncomment the appropriate line's in H's main.js config.

  • Dev mode: yarn storybook in R, yarn storybook in H in another terminal
  • Production: yarn build-storybook in R, yarn storybook in H in another terminal

Unit tests:

  • yarn test CsfFile

@nx-cloud
Copy link

nx-cloud bot commented May 15, 2021

Nx Cloud Report

CI ran the following commands for commit 02e7491. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

Status Command
#000000 nx run-many --target=prepare --all --parallel --max-parallel=15

Sent with 💌 from NxCloud.

@shilman shilman changed the title Core: Built-in stories.json extraction (WIP) Core: Built-in stories.json generation (WIP) May 15, 2021
Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. A bunch of smaller things

Comment on lines +8 to +13
interface ExtractedStory {
id: string;
kind: string;
name: string;
parameters: Record<string, any>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want to use our existing types for this? Last thing we need is yet-another-story type definition.

}
const csf = (await readCsf(csfFile)).parse();
csf.stories.forEach((story) => {
stories[story.id] = { ...story, kind: csf.meta.title };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be only pulling out the exact parameters we want here? Also will the csf tools eventually return other stuff on the story object apart from parameters?

Comment on lines +12 to +22
interface Meta {
title?: string;
includeStories?: string[] | RegExp;
excludeStories?: string[] | RegExp;
}

interface Story {
id: string;
name: string;
parameters: Record<string, any>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arggh more types

lib/csf-tools/src/CsfFile.ts Outdated Show resolved Hide resolved
lib/csf-tools/src/CsfFile.ts Outdated Show resolved Hide resolved
ExportDefaultDeclaration: {
enter({ node }) {
if (t.isObjectExpression(node.declaration)) {
// export default { ... };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about const meta = {}; export default meta;?

ExportNamedDeclaration: {
enter({ node }) {
if (t.isVariableDeclaration(node.declaration)) {
// export const X = ...;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about const Story = {}; export { Story }; }?

lib/csf-tools/src/CsfFile.ts Outdated Show resolved Hide resolved
@shilman shilman mentioned this pull request May 18, 2021
9 tasks
@shilman shilman requested a review from usulpro as a code owner May 18, 2021 01:32
@shilman shilman changed the title Core: Built-in stories.json generation (WIP) Core: Built-in static stories.json support May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants