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

Support configuration object for stories #182

Merged
merged 4 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/react/stories/EnvironmentVariables.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EnvironmentVariables } from './EnvironmentVariables';

export default {
title: 'Environment Variables',
component: EnvironmentVariables,
};

Expand Down
1 change: 0 additions & 1 deletion examples/react/stories/Header.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Header } from './Header';

export default {
title: 'Example/Header',
component: Header,
};

Expand Down
1 change: 0 additions & 1 deletion examples/react/stories/Page.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Page } from './Page';
import * as HeaderStories from './Header.stories';

export default {
title: 'Example/Page',
component: Page,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button } from './Button';

export default {
title: 'Example/Button',
component: Button,
argTypes: {
backgroundColor: { control: 'color' },
Expand Down
2 changes: 1 addition & 1 deletion examples/workspaces/packages/catalog/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
framework: '@storybook/react',
stories: ['../../app/stories/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
stories: [{ directory: '../../app/stories', titlePrefix: 'Example' }],
addons: ['@storybook/addon-a11y', '@storybook/addon-links', '@storybook/addon-essentials'],
core: {
builder: '@storybook/builder-vite',
Expand Down
21 changes: 10 additions & 11 deletions packages/builder-vite/list-stories.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import * as path from 'path';
import { promise as glob } from 'glob-promise';
import { normalizeStories } from '@storybook/core-common';

import type { Options, StoriesEntry } from '@storybook/core-common';
import type { Options } from '@storybook/core-common';

// TODO: Merge with https://github.com/storybookjs/builder-vite/pull/182
export async function listStories({ presets, configDir }: Options) {
export async function listStories(options: Options) {
return (
await Promise.all(
(
await presets.apply<Promise<StoriesEntry[]>>('stories')
).map((storiesEntry) => {
const files = typeof storiesEntry === 'string' ? storiesEntry : storiesEntry.files;
if (!files) {
return [] as string[];
}
return glob(path.isAbsolute(files) ? files : path.join(configDir, files));
normalizeStories(await options.presets.apply('stories', [], options), {
configDir: options.configDir,
workingDir: options.configDir,
}).map(({ directory, files }) => {
const pattern = path.join(directory, files);

return glob(path.isAbsolute(pattern) ? pattern : path.join(options.configDir, pattern));
})
)
).reduce((carry, stories) => carry.concat(stories), []);
Expand Down
4 changes: 2 additions & 2 deletions packages/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"dependencies": {
"@joshwooding/vite-plugin-react-docgen-typescript": "0.0.4",
"@mdx-js/mdx": "^1.6.22",
"@storybook/csf-tools": "^6.3.3",
"@storybook/source-loader": "^6.3.12",
"@storybook/csf-tools": "^6.4.3",
"@storybook/source-loader": "^6.4.3",
"@vitejs/plugin-react": "^1.0.8",
"ast-types": "^0.14.2",
"es-module-lexer": "^0.9.3",
Expand Down
Loading