-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kadirahq/file-watcher
Add file watcher
- Loading branch information
Showing
4 changed files
with
67 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export function filterStorybook(storybook, grep) { | ||
if(!grep || grep.length === 0 ){ | ||
return storybook | ||
} | ||
|
||
const filteredStorybook = []; | ||
for (const group of storybook) { | ||
const re = new RegExp(grep); | ||
if(re.test(group.kind)){ | ||
filteredStorybook.push(group); | ||
continue; | ||
} | ||
|
||
const filteredGroup = { | ||
kind: group.kind, | ||
stories: [] | ||
}; | ||
|
||
for (const story of group.stories) { | ||
if(re.test(story.name)){ | ||
filteredGroup.stories.push(story); | ||
continue; | ||
} | ||
} | ||
|
||
if(filteredGroup.stories.length > 0){ | ||
filteredStorybook.push(filteredGroup); | ||
} | ||
} | ||
|
||
return filteredStorybook; | ||
} |