mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
Server: Add json indexer to preset
Server: Add json indexer to preset Co-authored-by: Donnie Flood <donnie@floodfx.com>
This commit is contained in:
parent
0c12ac28ee
commit
f8cb089d65
@ -31,6 +31,11 @@
|
||||
"require": "./dist/config.js",
|
||||
"import": "./dist/config.mjs"
|
||||
},
|
||||
"./preset": {
|
||||
"types": "./dist/preset.d.ts",
|
||||
"require": "./dist/preset.js",
|
||||
"import": "./dist/preset.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
@ -49,9 +54,12 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@storybook/core-client": "7.1.0-alpha.12",
|
||||
"@storybook/csf": "^0.1.0",
|
||||
"@storybook/global": "^5.0.0",
|
||||
"@storybook/preview-api": "7.1.0-alpha.12",
|
||||
"@storybook/types": "7.1.0-alpha.12",
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"fs-extra": "^11.1.0",
|
||||
"ts-dedent": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -66,7 +74,8 @@
|
||||
"bundler": {
|
||||
"entries": [
|
||||
"./src/index.ts",
|
||||
"./src/config.ts"
|
||||
"./src/config.ts",
|
||||
"./src/preset.ts"
|
||||
],
|
||||
"platform": "browser"
|
||||
},
|
||||
|
1
code/renderers/server/preset.js
Normal file
1
code/renderers/server/preset.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./dist/preset');
|
33
code/renderers/server/src/preset.ts
Normal file
33
code/renderers/server/src/preset.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import fs from 'fs-extra';
|
||||
import { toId } from '@storybook/csf';
|
||||
import type { StaticMeta } from '@storybook/csf-tools';
|
||||
import type { IndexerOptions, IndexedStory, StoryIndexer } from '@storybook/types';
|
||||
|
||||
export const storyIndexers = (indexers: StoryIndexer[] | null) => {
|
||||
const jsonIndexer = async (fileName: string, opts: IndexerOptions) => {
|
||||
const json = await fs.readJson(fileName, 'utf-8');
|
||||
const meta: StaticMeta = {
|
||||
title: json.title,
|
||||
};
|
||||
const stories: IndexedStory[] = json.stories.map((story: any) => {
|
||||
const id = toId(meta.title, story.name);
|
||||
const { name } = story;
|
||||
const indexedStory: IndexedStory = {
|
||||
id,
|
||||
name,
|
||||
};
|
||||
return indexedStory;
|
||||
});
|
||||
return {
|
||||
meta,
|
||||
stories,
|
||||
};
|
||||
};
|
||||
return [
|
||||
{
|
||||
test: /(stories|story)\.json$/,
|
||||
indexer: jsonIndexer,
|
||||
},
|
||||
...(indexers || []),
|
||||
];
|
||||
};
|
@ -7051,9 +7051,12 @@ __metadata:
|
||||
resolution: "@storybook/server@workspace:renderers/server"
|
||||
dependencies:
|
||||
"@storybook/core-client": 7.1.0-alpha.12
|
||||
"@storybook/csf": ^0.1.0
|
||||
"@storybook/global": ^5.0.0
|
||||
"@storybook/preview-api": 7.1.0-alpha.12
|
||||
"@storybook/types": 7.1.0-alpha.12
|
||||
"@types/fs-extra": ^11.0.1
|
||||
fs-extra: ^11.1.0
|
||||
ts-dedent: ^2.0.0
|
||||
typescript: ~4.9.3
|
||||
languageName: unknown
|
||||
|
Loading…
x
Reference in New Issue
Block a user