CLI: generate preview.ts if applicable

This commit is contained in:
Yann Braga 2023-01-26 15:05:07 +01:00
parent 47a85e549c
commit a450809db1
2 changed files with 9 additions and 3 deletions

View File

@ -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 (

View File

@ -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)) {