Skip to content

Commit

Permalink
Merge pull request #23092 from storybookjs/shilman/count-onboarding-s…
Browse files Browse the repository at this point in the history
…tories

Telemetry: Count onboarding stories
(cherry picked from commit 9f151fc)
  • Loading branch information
shilman authored and github-actions[bot] committed Jun 15, 2023
1 parent 192115d commit 3a23694
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
70 changes: 70 additions & 0 deletions code/lib/core-server/src/utils/summarizeIndex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,66 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 3,
"exampleStoryCount": 8,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
"storyCount": 0,
"version": 4,
}
`);
});
it('onboarding stories', () => {
expect(
summarizeIndex({
v: 4,
entries: {
'example-introduction--docs': {
id: 'example-introduction--docs',
title: 'Example/Introduction',
name: 'Docs',
importPath: './src/stories/Introduction.mdx',
storiesImports: [],
type: 'docs',
tags: ['docs'],
},
'example-button--docs': {
id: 'example-button--docs',
title: 'Example/Button',
name: 'Docs',
importPath: './src/stories/Button.stories.ts',
type: 'docs',
tags: ['autodocs', 'docs'],
storiesImports: [],
},
'example-button--primary': {
id: 'example-button--primary',
title: 'Example/Button',
name: 'Primary',
importPath: './src/stories/Button.stories.ts',
tags: ['autodocs', 'story'],
type: 'story',
},
'example-button--warning': {
id: 'example-button--warning',
title: 'Example/Button',
name: 'Warning',
importPath: './src/stories/Button.stories.ts',
tags: ['autodocs', 'story'],
type: 'story',
},
},
})
).toMatchInlineSnapshot(`
Object {
"autodocsCount": 0,
"componentCount": 0,
"exampleDocsCount": 2,
"exampleStoryCount": 1,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 1,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -193,6 +253,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 0,
"exampleStoryCount": 0,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -248,6 +310,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 0,
"exampleStoryCount": 2,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 1,
"playStoryCount": 1,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -303,6 +367,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 0,
"exampleStoryCount": 0,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 1,
Expand Down Expand Up @@ -359,6 +425,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 1,
"exampleStoryCount": 2,
"mdxCount": 0,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down Expand Up @@ -408,6 +476,8 @@ describe('summarizeIndex', () => {
"exampleDocsCount": 1,
"exampleStoryCount": 0,
"mdxCount": 2,
"onboardingDocsCount": 0,
"onboardingStoryCount": 0,
"pageStoryCount": 0,
"playStoryCount": 0,
"storiesMdxCount": 0,
Expand Down
26 changes: 21 additions & 5 deletions code/lib/core-server/src/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const PAGE_REGEX = /(page|screen)/i;
export const isPageStory = (storyId: string) => PAGE_REGEX.test(storyId);

/**
* Filter out example stories that are generated by the CLI
* Is this story generated by the CLI
*/
const isExampleEntry = (entry: IndexEntry) => {
return [
const isCLIExampleEntry = (entry: IndexEntry) =>
[
'example-introduction--docs',
'configure-your-project--docs',
'example-button--docs',
'example-button--primary',
'example-button--secondary',
Expand All @@ -23,22 +24,35 @@ const isExampleEntry = (entry: IndexEntry) => {
'example-page--logged-in',
'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>();
let exampleStoryCount = 0;
let onboardingStoryCount = 0;
let onboardingDocsCount = 0;
let exampleDocsCount = 0;
let pageStoryCount = 0;
let playStoryCount = 0;
let autodocsCount = 0;
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 (isAnyExampleEntry(entry)) {
if (entry.type === 'story') onboardingStoryCount += 1;
if (entry.type === 'docs') onboardingDocsCount += 1;
} else if (entry.type === 'story') {
storyCount += 1;
componentTitles.add(entry.title);
Expand Down Expand Up @@ -69,6 +83,8 @@ export function summarizeIndex(storyIndex: StoryIndex) {
mdxCount,
exampleStoryCount,
exampleDocsCount,
onboardingStoryCount,
onboardingDocsCount,
version: storyIndex.v,
};
}

0 comments on commit 3a23694

Please sign in to comment.