diff --git a/code/lib/cli/src/generators/baseGenerator.ts b/code/lib/cli/src/generators/baseGenerator.ts index 999c533f0025..512e6dca5c9b 100644 --- a/code/lib/cli/src/generators/baseGenerator.ts +++ b/code/lib/cli/src/generators/baseGenerator.ts @@ -277,17 +277,17 @@ export async function baseGenerator( ); } - const packages = [ + const allPackages = [ 'storybook', getExternalFramework(rendererId) ? undefined : `@storybook/${rendererId}`, ...frameworkPackages, ...addonPackages, ...extraPackages, - ] - .filter(Boolean) - .filter( - (packageToInstall) => !installedDependencies.has(getPackageDetails(packageToInstall)[0]) - ); + ].filter(Boolean); + + const packages = [...new Set(allPackages)].filter( + (packageToInstall) => !installedDependencies.has(getPackageDetails(packageToInstall)[0]) + ); logger.log(); const versionedPackagesSpinner = ora({ @@ -299,30 +299,6 @@ export async function baseGenerator( ); versionedPackagesSpinner.succeed(); - await fse.ensureDir(`./${storybookConfigFolder}`); - - if (addMainFile) { - await configureMain({ - framework: { name: frameworkInclude, options: options.framework || {} }, - storybookConfigFolder, - docs: { autodocs: 'tag' }, - addons: pnp ? addons.map(wrapForPnp) : addons, - extensions, - language, - ...(staticDir ? { staticDirs: [path.join('..', staticDir)] } : null), - ...extraMain, - ...(type !== 'framework' - ? { - core: { - builder: builderInclude, - }, - } - : {}), - }); - } - - await configurePreview({ frameworkPreviewParts, storybookConfigFolder, language, rendererId }); - const depsToInstall = [...versionedPackages]; // Add basic babel config for a select few frameworks that need it, if they do not have a babel config file already @@ -385,6 +361,30 @@ export async function baseGenerator( addDependenciesSpinner.succeed(); } + await fse.ensureDir(`./${storybookConfigFolder}`); + + if (addMainFile) { + await configureMain({ + framework: { name: frameworkInclude, options: options.framework || {} }, + storybookConfigFolder, + docs: { autodocs: 'tag' }, + addons: pnp ? addons.map(wrapForPnp) : addons, + extensions, + language, + ...(staticDir ? { staticDirs: [path.join('..', staticDir)] } : null), + ...extraMain, + ...(type !== 'framework' + ? { + core: { + builder: builderInclude, + }, + } + : {}), + }); + } + + await configurePreview({ frameworkPreviewParts, storybookConfigFolder, language, rendererId }); + if (addScripts) { await stopIfExiting(async () => packageManager.addStorybookCommandInScripts({