Skip to content

Commit

Permalink
Merge pull request #28853 from storybookjs/norbert/fix-no-install-bug
Browse files Browse the repository at this point in the history
Bug: CLI `init` failure when `--no-install` passed fixed
(cherry picked from commit e5960ff)
  • Loading branch information
shilman committed Aug 13, 2024
1 parent dbea094 commit b82c7ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion code/core/src/core-server/utils/doTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import invariant from 'tiny-invariant';
import type { CoreConfig, Options, StoryIndex } from '@storybook/core/types';
import type { CoreConfig, Options } from '@storybook/core/types';
import { telemetry, getPrecedingUpgrade } from '@storybook/core/telemetry';
import { useStorybookMetadata } from './metadata';
import type { StoryIndexGenerator } from './StoryIndexGenerator';
Expand Down
6 changes: 4 additions & 2 deletions code/core/src/core-server/utils/save-story/save-story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { storyNameFromExport, toId } from '@storybook/csf';
import { printCsf, readCsf } from '@storybook/core/csf-tools';
import { logger } from '@storybook/core/node-logger';
import type { CoreConfig, Options } from '@storybook/core/types';
import { telemetry } from '@storybook/core/telemetry';
import { isExampleStoryId, telemetry } from '@storybook/core/telemetry';

import { basename, join } from 'node:path';
import { updateArgsInCsfFile } from './update-args-in-csf-file';
Expand Down Expand Up @@ -120,7 +120,9 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf
error: null,
} satisfies ResponseData<SaveStoryResponsePayload>);

if (!coreConfig.disableTelemetry) {
// don't take credit for save-from-controls actions against CLI example stories
const isCLIExample = isExampleStoryId(newStoryId ?? csfId);
if (!coreConfig.disableTelemetry && !isCLIExample) {
await telemetry('save-story', {
action: name ? 'createStory' : 'updateStory',
success: true,
Expand Down
12 changes: 2 additions & 10 deletions code/core/src/core-server/utils/summarizeIndex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isExampleStoryId } from '@storybook/core/telemetry';
import type { IndexEntry, StoryIndex } from '@storybook/core/types';

import { isMdxEntry, AUTODOCS_TAG, PLAY_FN_TAG } from './StoryIndexGenerator';
Expand Down Expand Up @@ -25,15 +26,6 @@ const isCLIExampleEntry = (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 @@ -49,7 +41,7 @@ export function summarizeIndex(storyIndex: StoryIndex) {
if (isCLIExampleEntry(entry)) {
if (entry.type === 'story') exampleStoryCount += 1;
if (entry.type === 'docs') exampleDocsCount += 1;
} else if (isAnyExampleEntry(entry)) {
} else if (isExampleStoryId(entry.id)) {
if (entry.type === 'story') onboardingStoryCount += 1;
if (entry.type === 'docs') onboardingDocsCount += 1;
} else if (entry.type === 'story') {
Expand Down
9 changes: 9 additions & 0 deletions code/core/src/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ export { getPrecedingUpgrade } from './event-cache';

export { addToGlobalContext } from './telemetry';

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

export const telemetry = async (
eventType: EventType,
payload: Payload = {},
Expand Down

0 comments on commit b82c7ca

Please sign in to comment.