From d9195f6025d351b0a769cf1924d569952853ff11 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 13 Jun 2023 09:40:17 +0200 Subject: [PATCH] Merge pull request #22502 from storybookjs/feat/generate-files-later-in-init CLI: Improve steps in storybook init (cherry picked from commit b50aa501c43ad3dc4ab5cf5497596fd0f7a914f9) --- code/lib/cli/src/generators/baseGenerator.ts | 60 ++++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) 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({