Skip to content

Commit

Permalink
Merge pull request #18574 from storybookjs/tom/sb-449-index-update-ge…
Browse files Browse the repository at this point in the history
…neration-to-produce

Addon-docs: Produce docs page entries in the index
  • Loading branch information
shilman authored Jul 7, 2022
2 parents 7acce54 + efa1d76 commit 060091b
Show file tree
Hide file tree
Showing 22 changed files with 735 additions and 125 deletions.
3 changes: 2 additions & 1 deletion addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function webpack(
return result;
}

export const storyIndexers = async (indexers?: StoryIndexer[]) => {
export const storyIndexers = async (indexers: StoryIndexer[] | null) => {
const mdxIndexer = async (fileName: string, opts: IndexerOptions) => {
let code = (await fs.readFile(fileName, 'utf-8')).toString();
// @ts-ignore
Expand All @@ -151,6 +151,7 @@ export const storyIndexers = async (indexers?: StoryIndexer[]) => {
{
test: /(stories|story)\.mdx$/,
indexer: mdxIndexer,
addDocsTemplate: true,
},
...(indexers || []),
];
Expand Down
5 changes: 5 additions & 0 deletions examples/react-ts/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const config: StorybookConfig = {
'@storybook/addon-storyshots',
'@storybook/addon-a11y',
],
docs: {
// enabled: false,
defaultName: 'Info',
// docsPage: false,
},
typescript: {
check: true,
checkOptions: {},
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
10 changes: 8 additions & 2 deletions lib/core-server/src/dev-server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import express, { Router } from 'express';
import compression from 'compression';

import type { CoreConfig, DocsOptions, Options, StorybookConfig } from '@storybook/core-common';
import { normalizeStories, logConfig } from '@storybook/core-common';
import {
CoreConfig,
DocsOptions,
Options,
StorybookConfig,
normalizeStories,
logConfig,
} from '@storybook/core-common';

import { telemetry } from '@storybook/telemetry';
import { getMiddleware } from './utils/middleware';
Expand Down
Loading

0 comments on commit 060091b

Please sign in to comment.