Add StoryStore.getStoriesJsonData()

This commit is contained in:
Tom Coleman 2021-09-06 07:49:21 +10:00
parent afcd33d110
commit 37e7c8f960

View File

@ -7,6 +7,8 @@ import {
GlobalAnnotations,
ComponentTitle,
} from '@storybook/csf';
import mapValues from 'lodash/mapValues';
import pick from 'lodash/pick';
import { StoriesListStore } from './StoriesListStore';
import { ArgsStore } from './ArgsStore';
@ -284,6 +286,22 @@ export class StoryStore<TFramework extends AnyFramework> {
};
}
// TODO -- do we need this?
getStoriesJsonData = () => {
const value = this.getSetStoriesPayload();
const allowedParameters = ['fileName', 'docsOnly', 'framework', '__id', '__isArgsStory'];
return {
v: 2,
globalParameters: pick(value.globalParameters, allowedParameters),
kindParameters: mapValues(value.kindParameters, (v) => pick(v, allowedParameters)),
stories: mapValues(value.stories, (v: any) => ({
...pick(v, ['id', 'name', 'kind', 'story']),
parameters: pick(v.parameters, allowedParameters),
})),
};
};
raw() {
return this.extract().map(({ id }: { id: StoryId }) => this.fromId(id));
}