Skip to content

Commit

Permalink
[Bug] titlePrefix in advanced story specifiers causes the story to cr…
Browse files Browse the repository at this point in the history
…ash with "Didn't find 'xyz' in CSF file"
  • Loading branch information
j3rem1e committed Sep 2, 2023
1 parent 45fcc33 commit d3474f9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
8 changes: 5 additions & 3 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import type { StorybookConfig } from '@storybook/svelte-vite';

const config: StorybookConfig = {
framework: '@storybook/svelte-vite',
stories: [
'../stories/**/*.stories.svelte',
],
stories: [{
directory: '../stories',
files:'**/*.stories.svelte',
titlePrefix:'Demo'
}],
addons: [
'../dist/preset/index.js',
'@storybook/addon-essentials',
Expand Down
4 changes: 0 additions & 4 deletions src/parser/extract-stories.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as svelte from 'svelte/compiler';
import type { Node } from 'estree';

import { storyNameFromExport, toId } from '@storybook/csf';

import dedent from 'dedent';
import { extractId } from './extract-id.js';

interface StoryDef {
storyId: string;
name: string;
template: boolean;
source: string;
Expand Down Expand Up @@ -131,7 +128,6 @@ export function extractStories(component: string): StoriesDef {
source = dedent`${component.substr(start, end - start)}`;
}
stories[isTemplate ? `tpl:${id}` : id] = {
storyId: toId(meta.id || meta.title || id, storyNameFromExport(id)),
name,
template: isTemplate,
source,
Expand Down
7 changes: 4 additions & 3 deletions src/preset/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as svelte from 'svelte/compiler';
import { extractStories } from '../parser/extract-stories.js';
import fs from 'fs-extra';
import { loadSvelteConfig } from '../config-loader.js';
import { storyNameFromExport, toId } from '@storybook/csf';

export async function svelteIndexer(fileName, { makeTitle }) {
let code = (await fs.readFile(fileName, 'utf-8')).toString();
Expand All @@ -13,13 +14,13 @@ export async function svelteIndexer(fileName, { makeTitle }) {
}

const defs = extractStories(code);

const meta = { ...defs.meta, title: makeTitle(defs.meta.title) };
return {
meta: { title: makeTitle(defs.meta.title) },
meta,
stories: Object.entries(defs.stories)
.filter(([id, story]) => !story.template)
.map(([id, story]) => ({
id: story.storyId,
id: toId(meta.id || meta.title || id, storyNameFromExport(id)),
name: story.name,
})),
};
Expand Down
2 changes: 1 addition & 1 deletion stories/button.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
</script>

<Meta title="Button" component={Button}/>
<Meta component={Button}/>

<Template let:args>
<Button {...args} on:click={handleClick}>
Expand Down

0 comments on commit d3474f9

Please sign in to comment.