@storybook/addon-svelte-csf 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as svelte from 'svelte/compiler';
|
|
2
|
-
import { storyNameFromExport, toId } from '@storybook/csf';
|
|
3
2
|
import dedent from 'dedent';
|
|
4
3
|
import { extractId } from './extract-id.js';
|
|
5
4
|
function getStaticAttribute(name, node) {
|
|
@@ -85,7 +84,6 @@ export function extractStories(component) {
|
|
|
85
84
|
source = dedent `${component.substr(start, end - start)}`;
|
|
86
85
|
}
|
|
87
86
|
stories[isTemplate ? `tpl:${id}` : id] = {
|
|
88
|
-
storyId: toId(meta.id || meta.title || id, storyNameFromExport(id)),
|
|
89
87
|
name,
|
|
90
88
|
template: isTemplate,
|
|
91
89
|
source,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import dedent from 'dedent';
|
|
2
1
|
import { extractStories } from './extract-stories.js';
|
|
3
2
|
import { fileURLToPath } from 'url';
|
|
4
3
|
import { readFileSync } from 'fs';
|
|
5
4
|
const parser = fileURLToPath(new URL('./collect-stories.js', import.meta.url))
|
|
6
|
-
.replace(/\\/g,
|
|
5
|
+
.replace(/\\/g, '/'); // For Windows paths;
|
|
7
6
|
// From https://github.com/sveltejs/svelte/blob/8db3e8d0297e052556f0b6dde310ef6e197b8d18/src/compiler/compile/utils/get_name_from_filename.ts
|
|
8
7
|
// Copied because it is not exported from the compiler
|
|
9
8
|
export function getNameFromFilename(filename) {
|
|
@@ -44,9 +43,7 @@ function transformSvelteStories(code) {
|
|
|
44
43
|
.map(([id]) => `export const ${id} = __storiesMetaData.stories[${JSON.stringify(id)}]`)
|
|
45
44
|
.join('\n');
|
|
46
45
|
const codeWithoutDefaultExport = code.replace('export default ', '//export default');
|
|
47
|
-
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
return dedent `${codeWithoutDefaultExport}
|
|
46
|
+
return `${codeWithoutDefaultExport}
|
|
50
47
|
const { default: parser } = require('${parser}');
|
|
51
48
|
const __storiesMetaData = parser(${componentName}, ${JSON.stringify(storiesDef)});
|
|
52
49
|
export default __storiesMetaData.meta;
|
package/dist/preset/indexer.d.ts
CHANGED
package/dist/preset/indexer.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as svelte from 'svelte/compiler';
|
|
|
2
2
|
import { extractStories } from '../parser/extract-stories.js';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import { loadSvelteConfig } from '../config-loader.js';
|
|
5
|
+
import { storyNameFromExport, toId } from '@storybook/csf';
|
|
5
6
|
export async function svelteIndexer(fileName, { makeTitle }) {
|
|
6
7
|
let code = (await fs.readFile(fileName, 'utf-8')).toString();
|
|
7
8
|
const svelteOptions = await loadSvelteConfig();
|
|
@@ -9,12 +10,13 @@ export async function svelteIndexer(fileName, { makeTitle }) {
|
|
|
9
10
|
code = (await svelte.preprocess(code, svelteOptions.preprocess, { filename: fileName })).code;
|
|
10
11
|
}
|
|
11
12
|
const defs = extractStories(code);
|
|
13
|
+
const meta = { ...defs.meta, title: makeTitle(defs.meta.title) };
|
|
12
14
|
return {
|
|
13
|
-
meta
|
|
15
|
+
meta,
|
|
14
16
|
stories: Object.entries(defs.stories)
|
|
15
17
|
.filter(([id, story]) => !story.template)
|
|
16
18
|
.map(([id, story]) => ({
|
|
17
|
-
id:
|
|
19
|
+
id: toId(meta.id || meta.title || id, storyNameFromExport(id)),
|
|
18
20
|
name: story.name,
|
|
19
21
|
})),
|
|
20
22
|
};
|