diff --git a/code/lib/cli/src/generators/baseGenerator.ts b/code/lib/cli/src/generators/baseGenerator.ts index d02a92c2806..09bbdcd2028 100644 --- a/code/lib/cli/src/generators/baseGenerator.ts +++ b/code/lib/cli/src/generators/baseGenerator.ts @@ -243,7 +243,7 @@ export async function baseGenerator( }); } - await configurePreview({ frameworkPreviewParts, storybookConfigFolder }); + await configurePreview({ frameworkPreviewParts, storybookConfigFolder, language }); // FIXME: temporary workaround for https://github.com/storybookjs/storybook/issues/17516 if ( diff --git a/code/lib/cli/src/generators/configure.ts b/code/lib/cli/src/generators/configure.ts index ef29c0136be..7da3b21507b 100644 --- a/code/lib/cli/src/generators/configure.ts +++ b/code/lib/cli/src/generators/configure.ts @@ -8,6 +8,7 @@ interface ConfigureMainOptions { commonJs?: boolean; staticDirs?: string[]; storybookConfigFolder: string; + language: SupportedLanguage; /** * Extra values for main.js * @@ -27,6 +28,7 @@ export interface FrameworkPreviewParts { interface ConfigurePreviewOptions { frameworkPreviewParts?: FrameworkPreviewParts; storybookConfigFolder: string; + language: SupportedLanguage; } export async function configureMain({ @@ -70,8 +72,12 @@ export async function configureMain({ } export async function configurePreview(options: ConfigurePreviewOptions) { - const { prefix = '' } = options?.frameworkPreviewParts || {}; - const previewPath = `./${options.storybookConfigFolder}/preview.js`; + const { prefix = '' } = options.frameworkPreviewParts || {}; + const isTypescript = + options.language === SupportedLanguage.TYPESCRIPT || + options.language === SupportedLanguage.TYPESCRIPT_LEGACY; + + const previewPath = `./${options.storybookConfigFolder}/preview.${isTypescript ? 'ts' : 'js'}`; // If the framework template included a preview then we have nothing to do if (await fse.pathExists(previewPath)) {