Skip to content

Commit

Permalink
Improve based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Jun 15, 2023
1 parent 9637c28 commit 8a424a0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions code/lib/core-server/src/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ const PAGE_REGEX = /(page|screen)/i;

export const isPageStory = (storyId: string) => PAGE_REGEX.test(storyId);

const isOnboardingEntry = (entry: IndexEntry) => ['example-button--warning'].includes(entry.id);

/**
* Filter out example stories that are generated by the CLI
* Is this story generated by the CLI
*/
const isExampleEntry = (entry: IndexEntry) =>
const isCLIExampleEntry = (entry: IndexEntry) =>
[
'example-introduction--docs',
'configure-your-project--docs',
'example-button--docs',
'example-button--primary',
'example-button--secondary',
Expand All @@ -26,6 +25,15 @@ const isExampleEntry = (entry: IndexEntry) =>
'example-page--logged-out',
].includes(entry.id);

/**
* Is this story part of the CLI generated examples,
* including user-created stories in those files
*/
const isAnyExampleEntry = (entry: IndexEntry) =>
entry.id.startsWith('example-button--') ||
entry.id.startsWith('example-header--') ||
entry.id.startsWith('example-page--');

export function summarizeIndex(storyIndex: StoryIndex) {
let storyCount = 0;
const componentTitles = new Set<string>();
Expand All @@ -39,10 +47,10 @@ export function summarizeIndex(storyIndex: StoryIndex) {
let storiesMdxCount = 0;
let mdxCount = 0;
Object.values(storyIndex.entries).forEach((entry) => {
if (isExampleEntry(entry)) {
if (isCLIExampleEntry(entry)) {
if (entry.type === 'story') exampleStoryCount += 1;
if (entry.type === 'docs') exampleDocsCount += 1;
} else if (isOnboardingEntry(entry)) {
} else if (isAnyExampleEntry(entry)) {
if (entry.type === 'story') onboardingStoryCount += 1;
if (entry.type === 'docs') onboardingDocsCount += 1;
} else if (entry.type === 'story') {
Expand Down

0 comments on commit 8a424a0

Please sign in to comment.