forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/subdirectory-routing' of github.com:dac09/redwood i…
…nto fix/subdirectory-routing * 'fix/subdirectory-routing' of github.com:dac09/redwood: Clarify the cell aliasing section of tutorial (redwoodjs#4964) s/posts/articles (redwoodjs#4971) fix(deps): update dependency cross-undici-fetch to v0.1.28 (redwoodjs#4966) Add Storybook template for i18n (redwoodjs#4764) Add @storybook/addon-essentials by default (redwoodjs#4765)
- Loading branch information
Showing
15 changed files
with
956 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/cli/src/commands/setup/i18n/templates/storybook.preview.js.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react' | ||
import { I18nextProvider } from 'react-i18next' | ||
import i18n from 'web/src/i18n' | ||
|
||
/** @type { import("@storybook/csf").GlobalTypes } */ | ||
export const globalTypes = { | ||
locale: { | ||
name: 'Locale', | ||
description: 'Internationalization locale', | ||
defaultValue: 'en', | ||
toolbar: { | ||
icon: 'globe', | ||
items: [ | ||
{ value: 'en', right: '🇺🇸', title: 'English' }, | ||
{ value: 'fr', right: '🇫🇷', title: 'Français' }, | ||
], | ||
}, | ||
}, | ||
} | ||
|
||
//** | ||
* We're following Storybook's naming convention here. See for example | ||
* https://github.com/storybookjs/addon-kit/blob/main/src/withGlobals.ts | ||
* Unfortunately that will make eslint complain, so we have to disable it when | ||
* using a hook below | ||
* | ||
* @param { import("@storybook/addons").StoryFn} StoryFn | ||
* @param { import("@storybook/addons").StoryContext} context | ||
* @returns a story wrapped in an I18nextProvider | ||
*/ | ||
const withI18n = (StoryFn, context) => { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
React.useEffect(() => { | ||
i18n.changeLanguage(context.globals.locale) | ||
}, [context.globals.locale]) | ||
|
||
return ( | ||
<I18nextProvider i18n={i18n}> | ||
<StoryFn /> | ||
</I18nextProvider> | ||
) | ||
} | ||
|
||
export const decorators = [withI18n] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
packages/cli/src/commands/setup/ui/tasks/configure-storybook.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import fs from 'fs-extra' | ||
|
||
import { getPaths } from '.' | ||
|
||
/** | ||
* Configure Storybook for the given template by creating a custom preview config | ||
*/ | ||
export default function configureStorybook({ force }, newStorybookPreview) { | ||
const storybookPreviewConfigPath = getPaths().web.storybookPreviewConfig | ||
|
||
let storybookPreviewConfig | ||
/** | ||
* Check if storybookPreviewConfigPath already exists. | ||
* Merge both files if it does. | ||
* By removing import react and export decorator from new config | ||
* And put new config inside current config after last import | ||
*/ | ||
if (fs.existsSync(storybookPreviewConfigPath)) { | ||
if (force) { | ||
fs.unlinkSync(storybookPreviewConfigPath) | ||
storybookPreviewConfig = newStorybookPreview | ||
} else { | ||
const currentConfig = fs | ||
.readFileSync(storybookPreviewConfigPath) | ||
.toString() | ||
|
||
const newDecoratorsName = newStorybookPreview.match( | ||
/export const decorators = \[(.*?)\]/ | ||
)[1] | ||
|
||
const currentDecoratorsName = currentConfig.match( | ||
/export const decorators = \[(.*?)\]/ | ||
)[1] | ||
|
||
const decoratorsExport = `export const decorators = [${currentDecoratorsName}, ${newDecoratorsName}]` | ||
|
||
const insideNewStorybookConfigWithoutReactAndDecoration = | ||
newStorybookPreview | ||
.replace(/import \* as React from 'react'/, '') | ||
.replace(/export const decorators = .*/, '') | ||
|
||
const currentConfigWithoutDecoration = currentConfig.replace( | ||
/export const decorators = .*/, | ||
'' | ||
) | ||
|
||
const reversedCurrentConfig = currentConfigWithoutDecoration | ||
.split('\n') | ||
.reverse() | ||
|
||
const indexOfLastImport = reversedCurrentConfig.findIndex((value) => | ||
/^import /.test(value) | ||
) | ||
reversedCurrentConfig.splice( | ||
indexOfLastImport, | ||
0, | ||
insideNewStorybookConfigWithoutReactAndDecoration | ||
) | ||
storybookPreviewConfig = | ||
reversedCurrentConfig.reverse().join(`\n`) + | ||
`\n` + | ||
currentConfig + | ||
`\n` + | ||
decoratorsExport | ||
} | ||
} else { | ||
storybookPreviewConfig = newStorybookPreview | ||
} | ||
|
||
fs.outputFileSync(storybookPreviewConfigPath, storybookPreviewConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.