Skip to content

Commit

Permalink
feat: save file name in store
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Feb 23, 2020
1 parent 9f8a5a9 commit 5de8627
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports.default = async function(source: string) {
const time = new Date();
const fileName = path.join(__dirname, 'story-store-data.js');
fs.utimesSync(fileName, time, time);
addStoriesKind(stories);
addStoriesKind(stories, this);
}
return source;
};
7 changes: 6 additions & 1 deletion core/loader/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loader } from 'webpack';
import { toId, storyNameFromExport } from '@storybook/csf';
import { StoriesGroup, Story } from '@component-controls/specification';
import { StoryStore, StoriesKind } from './types';
Expand All @@ -7,10 +8,14 @@ const store: StoryStore = {
stories: {},
};

export const addStoriesKind = (kind: StoriesGroup) => {
export const addStoriesKind = (
kind: StoriesGroup,
context: loader.LoaderContext,
) => {
let stories: StoriesKind;
if (kind.title) {
stories = {
fileName: context.resourcePath,
title: kind.title,
stories: [],
source: kind.source,
Expand Down
5 changes: 5 additions & 0 deletions core/loader/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export interface LoaderOptions {
}

export interface StoriesKind {
/**
* file name of the file of stories
*/
fileName?: string;

title: string;
stories: string[];
source?: string;
Expand Down

0 comments on commit 5de8627

Please sign in to comment.