mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-17 00:05:59 +08:00
# Conflicts: # addons/actions/package.json # addons/backgrounds/package.json # addons/events/package.json # addons/info/package.json # addons/jest/package.json # addons/knobs/package.json # addons/links/package.json # addons/notes/package.json # addons/options/package.json # addons/storyshots/storyshots-core/package.json # addons/storyshots/storyshots-puppeteer/package.json # addons/storysource/package.json # addons/viewport/package.json # app/angular/package.json # app/html/package.json # app/marko/package.json # app/mithril/package.json # app/polymer/package.json # app/react/package.json # app/vue/package.json # examples/cra-kitchen-sink/package.json # examples/html-kitchen-sink/package.json # examples/marko-cli/package.json # examples/mithril-kitchen-sink/package.json # examples/official-storybook/package.json # examples/vue-kitchen-sink/package.json # lib/cli/package.json # lib/cli/test/snapshots/angular-cli/package.json # lib/cli/test/snapshots/marko/package.json # lib/cli/test/snapshots/meteor/package.json # lib/cli/test/snapshots/mithril/package.json # lib/cli/test/snapshots/polymer/package.json # lib/cli/test/snapshots/react/package.json # lib/cli/test/snapshots/react_native/package.json # lib/cli/test/snapshots/react_native_scripts/package.json # lib/cli/test/snapshots/react_project/package.json # lib/cli/test/snapshots/react_scripts/package.json # lib/cli/test/snapshots/sfc_vue/package.json # lib/cli/test/snapshots/update_package_organisations/package.json # lib/cli/test/snapshots/vue/package.json # lib/cli/test/snapshots/webpack_react/package.json # lib/core/package.json # yarn.lock
Storybook Codemods
Storybook Codemods is a collection of codemod scripts written with JSCodeshift. It will help you migrate breaking changes & deprecations.
Installation
npm install jscodeshift
npm install @storybook/codemod
@storybook/codemod
is our collection of codemod scripts.jscodeshift
is a tool we use to apply our codemods.
After running the migration commands, you can remove them from your package.json
, if you added them.
How to run a codemod script
From the directory where you installed both jscodeshift
and @storybook/codemod
run:
Example:
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/update-organisation-name.js . --ignore-pattern "node_modules|dist"
Explanation:
<jscodeShiftCommand> -t <transformFileLocation> <pathToSource> --ignore-pattern "<globPatternToIgnore>"
Transforms
update-organisation-name
Updates package names in imports to migrate to the new package names of storybook.
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/update-organisation-name.js . --ignore-pattern "node_modules|dist"
There's a mapping of paths we replace but this example explains the gist of it:
Example:
import { storiesOf } from '@kadira/storybook';
import { linkTo } from '@kadira/storybook-addon-links';
Becomes
import { storiesOf } from '@storybook/react';
import { linkTo } from '@storybook/addon-links';
update-addon-info
Replaces the Info addon's deprecated addWithInfo
API with the standard withInfo
API.
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/update-addon-info.js . --ignore-pattern "node_modules|dist"
Simple example:
storiesOf('Button').addWithInfo(
'simple usage',
'This is the basic usage of the button.',
() => (
<Button label="The Button" />
)
)
Becomes
storiesOf('Button').add('simple usage', withInfo(
'This is the basic usage of the button.'
)(() => (
<Button label="The Button" />
)))
With options example:
storiesOf('Button').addWithInfo(
'simple usage (disable source)',
'This is the basic usage of the button.',
() => (
<Button label="The Button" />
),
{ source: false, inline: true }
)
Becomes
storiesOf('Button').add('simple usage (disable source)', withInfo({
text: 'This is the basic usage of the button.',
source: false,
inline: true
})(() => (
<Button label="The Button" />
)))