Skip to content

Commit

Permalink
Merge pull request #65 from MentorMate/chore/storybook-examples-option
Browse files Browse the repository at this point in the history
Chore: add storybook examples option
  • Loading branch information
NikolayDonev authored Mar 26, 2024
2 parents 6065cb7 + 0d5ebdc commit af3f8ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
26 changes: 15 additions & 11 deletions src/commands/start-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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'));
Expand Down
23 changes: 15 additions & 8 deletions src/tools/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
};

Expand All @@ -82,11 +84,12 @@ export const SelectionToTemplateParamsMap: Partial<Record<
[StyleLibraryChoice.StyledComponents]: {
hasStyledComponents: true
},
[StorybookChoice.withStorybook]: {
hasStorybook: true
[StorybookChoice.Storybook]: {
hasStorybook: true,
},
[StorybookChoice.withoutStorybook]: {
hasStorybook: false
[StorybookChoice.StorybookWithStories]: {
hasStorybook: true,
hasStorybookExample: true
},
[StateLibraryChoice.ReduxToolkit]: {
hasReduxToolkit: true
Expand Down Expand Up @@ -119,7 +122,10 @@ const getFileNameMatcher = (fileName: string) => {
// 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')
],
Expand Down Expand Up @@ -152,6 +158,7 @@ export const DefaultTemplateParams: TemplateParams = {
hasGluestackUIEjected: false,
hasStyledComponents: false,
hasStorybook: false,
hasStorybookExample: false,
hasReduxToolkit: false,
hasRTKQuery: false,
hasReactotron: false,
Expand Down
1 change: 1 addition & 0 deletions src/types/BaseProjectTemplateParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface TemplateParams {
hasGluestackUIDefaultTheme: boolean;
hasGluestackUIEjected: boolean;
hasStorybook: boolean;
hasStorybookExample: boolean;
hasReduxToolkit: boolean;
hasRTKQuery: boolean;
hasStyledComponents: boolean;
Expand Down

0 comments on commit af3f8ef

Please sign in to comment.