From 0d5ebdce53d748217815197b163860f405b51fa6 Mon Sep 17 00:00:00 2001 From: Gergana Ivanova Date: Tue, 26 Mar 2024 14:44:11 +0200 Subject: [PATCH] chore: add storybook examples option --- src/commands/start-project.ts | 26 +++++++++++++++----------- src/tools/options.ts | 23 +++++++++++++++-------- src/types/BaseProjectTemplateParams.ts | 1 + 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/commands/start-project.ts b/src/commands/start-project.ts index 803ea98..5594fdd 100644 --- a/src/commands/start-project.ts +++ b/src/commands/start-project.ts @@ -112,7 +112,7 @@ const startProject = async (toolbox: RnBootstrapToolbox) => { } } - if (selectedOptions.storybook === StorybookChoice.withStorybook) { + if (selectedOptions.storybook !== StorybookChoice.NoStorybook) { print.highlight('Creating storybook...'); await spawnProgress('npx sb@latest init'); @@ -125,18 +125,22 @@ const startProject = async (toolbox: RnBootstrapToolbox) => { jsonIndent: 2 }); - if (gluestackOptions.includes(selectedOptions.styleLibrary)) { - // Replace storybook files with preconfigured ones specific for gluestack - replaceFile('preview.tsx', '.storybook/preview.tsx'); + if (selectedOptions.storybook === StorybookChoice.StorybookWithStories) { + if (gluestackOptions.includes(selectedOptions.styleLibrary)) { + // Replace storybook files with preconfigured ones specific for gluestack + replaceFile('preview.tsx', '.storybook/preview.tsx'); + filesystem.remove('.storybook/stories/'); + replaceFile('gluestackStories', '.storybook/stories'); + } + + print.info('Removing storybook config folder reference...'); + toolbox.filesystem.remove('config/storybook'); + print.highlight( + print.checkmark + ' Storybook config folder reference removed!' + ); + } else { filesystem.remove('.storybook/stories/'); - replaceFile('gluestackStories', '.storybook/stories'); } - - print.info('Removing storybook config folder reference...'); - toolbox.filesystem.remove('config/storybook'); - print.highlight( - print.checkmark + ' Storybook config folder reference removed!' - ); } IS_MAC && (await yarn.run('pod-install')); diff --git a/src/tools/options.ts b/src/tools/options.ts index 11d0d4c..9064ce6 100644 --- a/src/tools/options.ts +++ b/src/tools/options.ts @@ -21,8 +21,9 @@ export enum StyleLibraryChoice { } export enum StorybookChoice { - withStorybook = 'Yes', - withoutStorybook = 'No' + Storybook = 'Storybook no examples', + StorybookWithStories = 'Storybook with Stories example', + NoStorybook = 'No Storybook' } export enum StateLibraryChoice { @@ -55,7 +56,8 @@ export const SelectionToDependencyNameMap = { export const SelectionToDevDependencyNameMap = { [StyleLibraryChoice.StyledComponents]: styleDevDeps, - [StorybookChoice.withStorybook]: storybookDevDeps, + [StorybookChoice.Storybook]: storybookDevDeps, + [StorybookChoice.StorybookWithStories]: storybookDevDeps, [ReactotronChoice.withReactotron]: reactotronDevDeps }; @@ -82,11 +84,12 @@ export const SelectionToTemplateParamsMap: Partial { // Paths from unselected options get skipped when copying the baseProject // You can also specify individual file names as strings export const SelectionToOptionalFilePathsMap = { - [StorybookChoice.withStorybook]: [ + [StorybookChoice.Storybook]: [ + getFileNameMatcher('App.storybook.tsx') + ], + [StorybookChoice.StorybookWithStories]: [ getFullPathMatcher('config/storybook/'), getFileNameMatcher('App.storybook.tsx') ], @@ -152,6 +158,7 @@ export const DefaultTemplateParams: TemplateParams = { hasGluestackUIEjected: false, hasStyledComponents: false, hasStorybook: false, + hasStorybookExample: false, hasReduxToolkit: false, hasRTKQuery: false, hasReactotron: false, diff --git a/src/types/BaseProjectTemplateParams.ts b/src/types/BaseProjectTemplateParams.ts index df42b80..e89b63d 100644 --- a/src/types/BaseProjectTemplateParams.ts +++ b/src/types/BaseProjectTemplateParams.ts @@ -4,6 +4,7 @@ export interface TemplateParams { hasGluestackUIDefaultTheme: boolean; hasGluestackUIEjected: boolean; hasStorybook: boolean; + hasStorybookExample: boolean; hasReduxToolkit: boolean; hasRTKQuery: boolean; hasStyledComponents: boolean;