mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Codemod: Rename Module format to CSF and shorten codemod names
This commit is contained in:
parent
d7410b0268
commit
a54263e329
@ -77,7 +77,7 @@ storiesOf('Button', module).add(
|
||||
|
||||
## Legacy loading
|
||||
|
||||
With the module format, we introduced a `load` API. To load the all `.stories.js` files, including `storiesOf` files, simply run the following in your Storybook config file:
|
||||
With the Component Story Format (CSF), we introduced a `load` API. To load the all `.stories.js` files, including `storiesOf` files, simply run the following in your Storybook config file:
|
||||
|
||||
```js
|
||||
import { load } from '@storybook/react';
|
||||
|
@ -151,14 +151,14 @@ Heuristics:
|
||||
- The storiesOf "kind" name must be Button
|
||||
- Button must be imported in the file
|
||||
|
||||
### convert-storiesof-to-module
|
||||
### storiesof-to-csf
|
||||
|
||||
This converts all of your "old-style" `storiesOf` stories into component module format, which uses standard ES6 modules.
|
||||
This converts all of your "old-style" `storiesOf` stories into Component Story Format (CSF), which uses standard ES6 modules.
|
||||
|
||||
> NOTE: The output of this transformation may require manual editing after running the transformation. `storiesOf` format allows multiple "kinds" (components) to be declared per file, but module format only allows a single component per file. Therefore, if you use this feature in your input stories, you will need to split up the resulting outputs by hand. You'll see a warning at the console if you need to hand edit.
|
||||
> NOTE: The output of this transformation may require manual editing after running the transformation. `storiesOf` API allows multiple "kinds" (components) to be declared per file, but CSF only allows a single component per file. Therefore, if you use this feature in your input stories, you will need to split up the resulting outputs by hand. You'll see a warning at the console if you need to hand edit.
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/convert-storiesof-to-module.js . --ignore-pattern "node_modules|dist"
|
||||
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/storiesof-to-csf.js . --ignore-pattern "node_modules|dist"
|
||||
```
|
||||
|
||||
For example:
|
||||
@ -201,14 +201,14 @@ Heuristics:
|
||||
- If a file has any default export, it will be skipped
|
||||
- If a file has multiple `storiesOf` declarations, it will convert each one separately. This generates invalid ES6, but you can edit the file by hand to split it into multiple files (or whatever is appropriate).
|
||||
|
||||
### convert-module-to-mdx
|
||||
### csf-to-mdx
|
||||
|
||||
This converts all of your component module stories into MDX format, which integrates story examples and long-form documentation.
|
||||
This converts all of your CSF Component Stories into MDX syntax, which integrates story examples and long-form documentation.
|
||||
|
||||
> NOTE: The output of this transformation may require manual editing after running the transformation. MDX is finnicky about the top-level statements it allows. For example, [variables should be defined with exports](https://mdxjs.com/getting-started/#defining-variables-with-exports), meaning `const foo = 5;` should be rewritten as `export const foo = 5;`. We don't do this transformation automatically, since you may prefer to refactor your stories.
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/convert-to-module-format.js . --ignore-pattern "node_modules|dist"
|
||||
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/csf-to-mdxt.js . --ignore-pattern "node_modules|dist"
|
||||
```
|
||||
|
||||
For example:
|
||||
@ -240,12 +240,12 @@ import { Meta, Story } from '@storybook/addon-docs/blocks';
|
||||
</Story>
|
||||
```
|
||||
|
||||
### convert-mdx-to-module
|
||||
### mdx-to-csf
|
||||
|
||||
This converts all your MDX stories into module format.
|
||||
This converts all your MDX stories into Component Story Format.
|
||||
|
||||
```sh
|
||||
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/convert-to-module-format.js . --ignore-pattern "node_modules|dist" --extensions=mdx
|
||||
./node_modules/.bin/jscodeshift -t ./node_modules/@storybook/codemod/dist/transforms/mdx-to-csf.js . --ignore-pattern "node_modules|dist" --extensions=mdx
|
||||
```
|
||||
|
||||
For example:
|
||||
@ -262,7 +262,7 @@ import { Meta, Story } from '@storybook/addon-docs/blocks';
|
||||
|
||||
Becomes:
|
||||
|
||||
```
|
||||
```js
|
||||
import React from 'react';
|
||||
import Button from './Button';
|
||||
|
||||
|
@ -10,5 +10,5 @@ const testNames = [
|
||||
];
|
||||
|
||||
testNames.forEach(testName => {
|
||||
defineTest(__dirname, `convert-module-to-mdx`, null, `convert-module-to-mdx/${testName}`);
|
||||
defineTest(__dirname, `csf-to-mdx`, null, `csf-to-mdx/${testName}`);
|
||||
});
|
@ -12,5 +12,5 @@ const testNames = [
|
||||
];
|
||||
|
||||
testNames.forEach(testName => {
|
||||
defineTest(__dirname, `convert-mdx-to-module`, null, `convert-mdx-to-module/${testName}`);
|
||||
defineTest(__dirname, `mdx-to-csf`, null, `mdx-to-csf/${testName}`);
|
||||
});
|
@ -17,10 +17,5 @@ const testNames = [
|
||||
];
|
||||
|
||||
testNames.forEach(testName => {
|
||||
defineTest(
|
||||
__dirname,
|
||||
`convert-storiesof-to-module`,
|
||||
null,
|
||||
`convert-storiesof-to-module/${testName}`
|
||||
);
|
||||
defineTest(__dirname, `storiesof-to-csf`, null, `storiesof-to-csf/${testName}`);
|
||||
});
|
@ -4,7 +4,7 @@ import { logger } from '@storybook/node-logger';
|
||||
import { isReserved } from '../lib/isReserved';
|
||||
|
||||
/**
|
||||
* Convert a legacy story file to module format
|
||||
* Convert a legacy story API to component story format
|
||||
*
|
||||
* For example:
|
||||
*
|
Loading…
x
Reference in New Issue
Block a user