Skip to content

Commit

Permalink
Add telemetry for successful scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Lloyd committed Dec 8, 2023
1 parent 8a2baff commit cc81dad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ async function doInitiate(
// Check if the current directory is empty.
if (options.force !== true && currentDirectoryIsEmpty(packageManager.type)) {
// Prompt the user to create a new project from our list.
await scaffoldNewProject(packageManager.type);
await scaffoldNewProject(packageManager.type, options);

if (process.env.IN_STORYBOOK_SANDBOX === 'true' || process.env.CI === 'true') {
packageManager.addPackageResolutions({
Expand Down
26 changes: 20 additions & 6 deletions code/lib/cli/src/scaffold-new-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { readdirSync, remove } from 'fs-extra';
import prompts from 'prompts';
import dedent from 'ts-dedent';

import { telemetry } from '@storybook/telemetry';

import { GenerateNewProjectOnInitError } from '@storybook/core-events/server-errors';
import { logger } from '@storybook/node-logger';

import type { PackageManagerName } from './js-package-manager';
import type { CommandOptions } from './generators/types';

type CoercedPackageManagerName = 'npm' | 'yarn' | 'pnpm';

Expand Down Expand Up @@ -108,7 +111,10 @@ const buildProjectDisplayNameForPrint = ({ displayName }: SupportedProject) => {
*
* @param packageManager The package manager to use.
*/
export const scaffoldNewProject = async (packageManager: PackageManagerName) => {
export const scaffoldNewProject = async (
packageManager: PackageManagerName,
{ disableTelemetry }: CommandOptions
) => {
const packageManagerName = packageManagerToCoercedName(packageManager);

logger.plain(
Expand All @@ -135,7 +141,7 @@ export const scaffoldNewProject = async (packageManager: PackageManagerName) =>
let projectStrategy;

if (process.env.STORYBOOK_INIT_EMPTY_TYPE) {
projectStrategy = SUPPORTED_PROJECTS[process.env.STORYBOOK_INIT_EMPTY_TYPE];
projectStrategy = process.env.STORYBOOK_INIT_EMPTY_TYPE;
}

if (!projectStrategy) {
Expand All @@ -152,11 +158,12 @@ export const scaffoldNewProject = async (packageManager: PackageManagerName) =>
{ onCancel: () => process.exit(0) }
);

projectStrategy = SUPPORTED_PROJECTS[project];
projectStrategy = project;
}

const projectDisplayName = buildProjectDisplayNameForPrint(projectStrategy);
const createScript = projectStrategy.createScript[packageManagerName];
const projectStrategyConfig = SUPPORTED_PROJECTS[projectStrategy];
const projectDisplayName = buildProjectDisplayNameForPrint(projectStrategyConfig);
const createScript = projectStrategyConfig.createScript[packageManagerName];

logger.line(1);
logger.plain(
Expand All @@ -182,7 +189,14 @@ export const scaffoldNewProject = async (packageManager: PackageManagerName) =>
throw new GenerateNewProjectOnInitError({
error: e,
packageManager: packageManagerName,
projectType: projectDisplayName,
projectType: projectStrategy,
});
}

if (!disableTelemetry) {
telemetry('scaffolded-empty', {
packageManager: packageManagerName,
projectType: projectStrategy,
});
}

Expand Down
1 change: 1 addition & 0 deletions code/lib/telemetry/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type EventType =
| 'build'
| 'upgrade'
| 'init'
| 'scaffolded-empty'
| 'browser'
| 'canceled'
| 'error'
Expand Down

0 comments on commit cc81dad

Please sign in to comment.