Skip to content

Commit

Permalink
Update StoryIndexGenerator to generate "template" entries
Browse files Browse the repository at this point in the history
Template (standalone: false) entries are needed for:
  - Docs Page
  - *.stories.mdx files that define a docs page and stories.

A Template entry expects to be rendered from and against a story file. (A standalone entry expects to be rendered as a MDX file)
  • Loading branch information
tmeasday committed Jul 7, 2022
1 parent 223bfe6 commit 0dd08bb
Show file tree
Hide file tree
Showing 19 changed files with 718 additions and 121 deletions.
1 change: 1 addition & 0 deletions addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const storyIndexers = async (indexers: StoryIndexer[] | null) => {
{
test: /(stories|story)\.mdx$/,
indexer: mdxIndexer,
addDocsTemplate: true,
},
...(indexers || []),
];
Expand Down
8 changes: 7 additions & 1 deletion lib/addons/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ export type StoryIndexEntry = BaseIndexEntry & {
export type DocsIndexEntry = BaseIndexEntry & {
storiesImports: Path[];
type: 'docs';
legacy?: boolean;
standalone: boolean;
};

/** A StandaloneDocsIndexExtry represents a file who's default export is directly renderable */
export type StandaloneDocsIndexEntry = DocsIndexEntry & { standalone: true };
/** A TemplateDocsIndexEntry represents a stories file that gets rendered in "docs" mode */
export type TemplateDocsIndexEntry = DocsIndexEntry & { standalone: false };

export type IndexEntry = StoryIndexEntry | DocsIndexEntry;

// The `any` here is the story store's `StoreItem` record. Ideally we should probably only
Expand Down
1 change: 1 addition & 0 deletions lib/core-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export interface StoryIndex {
export interface StoryIndexer {
test: RegExp;
indexer: (fileName: string, options: IndexerOptions) => Promise<StoryIndex>;
addDocsTemplate?: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@storybook/core-events": "7.0.0-alpha.11",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf-tools": "7.0.0-alpha.11",
"@storybook/docs-mdx": "0.0.1-canary.1.4bea5cc.0",
"@storybook/docs-mdx": "0.0.1-canary.12433cf.0",
"@storybook/node-logger": "7.0.0-alpha.11",
"@storybook/semver": "^7.3.2",
"@storybook/store": "7.0.0-alpha.11",
Expand Down
Loading

0 comments on commit 0dd08bb

Please sign in to comment.