From 2783ab3ddc59187df928273ce68849c87cb29193 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 10 May 2023 15:22:02 +0200 Subject: [PATCH] switch order of actions in baseGenerator 1. install dependencies 2. on success, write storybook config files --- code/lib/cli/src/generators/baseGenerator.ts | 54 ++++++++++---------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/code/lib/cli/src/generators/baseGenerator.ts b/code/lib/cli/src/generators/baseGenerator.ts index 9a44785b7146..d57f8b7bfa0f 100644 --- a/code/lib/cli/src/generators/baseGenerator.ts +++ b/code/lib/cli/src/generators/baseGenerator.ts @@ -222,13 +222,15 @@ export async function baseGenerator( ); } - const packages = [ + const allPackages = [ 'storybook', getExternalFramework(rendererId) ? undefined : `@storybook/${rendererId}`, ...frameworkPackages, ...addonPackages, ...extraPackages, - ] + ]; + + const packages = [...new Set(allPackages)] .filter(Boolean) .filter( (packageToInstall) => !installedDependencies.has(getPackageDetails(packageToInstall)[0]) @@ -236,30 +238,6 @@ export async function baseGenerator( const versionedPackages = await packageManager.getVersionedPackages(packages); - 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 babelDependencies = addBabel && builder !== CoreBuilder.Vite ? await getBabelDependencies(packageManager, packageJson) @@ -287,6 +265,30 @@ export async function baseGenerator( await packageManager.addESLintConfig(); } + 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 (addComponents) { const templateLocation = hasFrameworkTemplates(framework) ? framework : rendererId; await copyTemplateFiles({