-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codemod: convert mdx to module format #7419
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b0cfb29
Codemod: convert MDX back to module format
shilman 746e98f
Merge branch 'next' into 7101-convert-mdx-to-module
shilman d50c383
Codemod: convert-mdx-to-module add story ref test case
shilman cfc658c
Fix plaintext story corner case
shilman 2111ffc
Merge branch 'next' into 7101-convert-mdx-to-module
shilman 35104a9
Merge branch '7101-mdx-format-codemod' into 7101-convert-mdx-to-module
shilman da38fc4
Merge branch 'next' into 7101-convert-mdx-to-module
shilman f34bca6
Merge branch 'next' into 7101-convert-mdx-to-module
shilman c2588f9
Migration bugfixes
shilman ac405a0
Update codemod test fixtures for React bugfix
shilman 3b700fe
Merge branch 'next' into 7101-convert-mdx-to-module
shilman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions
14
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/basic.input.js
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,14 @@ | ||
import Button from './Button'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Meta, Story } from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta title='Button' /> | ||
|
||
<Story name='story1'><Button label='Story 1' /></Story> | ||
|
||
<Story name='second story'><Button label='Story 2' onClick={action('click')} /></Story> | ||
|
||
<Story name='complex story'><div> | ||
<Button label='The Button' onClick={action('onClick')} /> | ||
<br /> | ||
</div></Story> |
25 changes: 25 additions & 0 deletions
25
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/basic.output.js
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,25 @@ | ||
import React from 'react'; | ||
import Button from './Button'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
export default { | ||
title: 'Button', | ||
}; | ||
|
||
export const story1 = () => <Button label="Story 1" />; | ||
export const secondStory = () => <Button label="Story 2" onClick={action('click')} />; | ||
|
||
secondStory.story = { | ||
name: 'second story', | ||
}; | ||
|
||
export const complexStory = () => ( | ||
<div> | ||
<Button label="The Button" onClick={action('onClick')} /> | ||
<br /> | ||
</div> | ||
); | ||
|
||
complexStory.story = { | ||
name: 'complex story', | ||
}; |
8 changes: 8 additions & 0 deletions
8
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/decorators.input.js
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,8 @@ | ||
import Button from './Button'; | ||
import { Meta, Story } from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta | ||
title='Some.Button' | ||
decorators={[withKnobs, storyFn => <div className='foo'>{storyFn}</div>]} /> | ||
|
||
<Story name='with decorator'><Button label='The Button' /></Story> |
13 changes: 13 additions & 0 deletions
13
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/decorators.output.js
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,13 @@ | ||
import React from 'react'; | ||
import Button from './Button'; | ||
|
||
export default { | ||
title: 'Some.Button', | ||
decorators: [withKnobs, storyFn => <div className="foo">{storyFn}</div>], | ||
}; | ||
|
||
export const withDecorator = () => <Button label="The Button" />; | ||
|
||
withDecorator.story = { | ||
name: 'with decorator', | ||
}; |
19 changes: 19 additions & 0 deletions
19
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/exclude-stories.input.js
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,19 @@ | ||
import Button from './Button'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Meta, Story } from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta title='Button' /> | ||
|
||
export const rowData = { | ||
col1: 'a', | ||
col2: 2, | ||
}; | ||
|
||
<Story name='story1'><Button label='Story 1' /></Story> | ||
|
||
<Story name='second story'><Button label='Story 2' onClick={action('click')} /></Story> | ||
|
||
<Story name='complex story'><div> | ||
<Button label='The Button' onClick={action('onClick')} /> | ||
<br /> | ||
</div></Story> |
30 changes: 30 additions & 0 deletions
30
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/exclude-stories.output.js
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,30 @@ | ||
import React from 'react'; | ||
import Button from './Button'; | ||
import { action } from '@storybook/addon-actions'; | ||
export const rowData = { | ||
col1: 'a', | ||
col2: 2, | ||
}; | ||
|
||
export default { | ||
title: 'Button', | ||
includeStories: ['story1', 'secondStory', 'complexStory'], | ||
}; | ||
|
||
export const story1 = () => <Button label="Story 1" />; | ||
export const secondStory = () => <Button label="Story 2" onClick={action('click')} />; | ||
|
||
secondStory.story = { | ||
name: 'second story', | ||
}; | ||
|
||
export const complexStory = () => ( | ||
<div> | ||
<Button label="The Button" onClick={action('onClick')} /> | ||
<br /> | ||
</div> | ||
); | ||
|
||
complexStory.story = { | ||
name: 'complex story', | ||
}; |
14 changes: 14 additions & 0 deletions
14
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/parameters.input.js
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,14 @@ | ||
import React from 'react'; | ||
import Button from './Button'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { Meta, Story } from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta | ||
title='Button' | ||
parameters={{ | ||
component: Button, | ||
foo: 1, | ||
bar: 2, | ||
}} /> | ||
|
||
<Story name='with kind parameters'><Button label='The Button' /></Story> |
19 changes: 19 additions & 0 deletions
19
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/parameters.output.js
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,19 @@ | ||
import React from 'react'; | ||
import Button from './Button'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
export default { | ||
title: 'Button', | ||
|
||
parameters: { | ||
component: Button, | ||
foo: 1, | ||
bar: 2, | ||
}, | ||
}; | ||
|
||
export const withKindParameters = () => <Button label="The Button" />; | ||
|
||
withKindParameters.story = { | ||
name: 'with kind parameters', | ||
}; |
3 changes: 3 additions & 0 deletions
3
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/plaintext.input.js
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,3 @@ | ||
import { Story, Meta } from '@storybook/addon-docs/blocks'; | ||
|
||
<Story name="plaintext">Plain text</Story>; |
3 changes: 3 additions & 0 deletions
3
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/plaintext.output.js
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,3 @@ | ||
import React from 'react'; | ||
export default {}; | ||
export const plaintext = () => 'Plain text'; |
18 changes: 18 additions & 0 deletions
18
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/story-parameters.input.js
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,18 @@ | ||
import Button from './Button'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { Meta, Story } from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta title='Button' /> | ||
|
||
<Story | ||
name='with story parameters' | ||
parameters={{ | ||
header: false, | ||
inline: true, | ||
}}><Button label='The Button' /></Story> | ||
|
||
<Story | ||
name='foo' | ||
parameters={{ | ||
bar: 1, | ||
}}><Button label='Foo' /></Story> |
26 changes: 26 additions & 0 deletions
26
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/story-parameters.output.js
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,26 @@ | ||
import React from 'react'; | ||
import Button from './Button'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
export default { | ||
title: 'Button', | ||
}; | ||
|
||
export const withStoryParameters = () => <Button label="The Button" />; | ||
|
||
withStoryParameters.story = { | ||
name: 'with story parameters', | ||
|
||
parameters: { | ||
header: false, | ||
inline: true, | ||
}, | ||
}; | ||
|
||
export const foo = () => <Button label="Foo" />; | ||
|
||
foo.story = { | ||
parameters: { | ||
bar: 1, | ||
}, | ||
}; |
21 changes: 21 additions & 0 deletions
21
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/story-refs.input.js
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,21 @@ | ||
import { Story, Meta } from '@storybook/addon-docs/blocks'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Button } from '@storybook/react/demo'; | ||
|
||
<Meta | ||
title="Addons|Docs/mdx" | ||
decorators={[storyFn => <div style={{ backgroundColor: 'yellow' }}>{storyFn()}</div>]} | ||
parameters={{ component: Button, notes: 'component notes' }} | ||
/> | ||
|
||
## Getting into details | ||
|
||
<Story name="solo story"> | ||
<Button onClick={action('clicked')}>solo</Button> | ||
</Story> | ||
|
||
<Source name="hello story" /> | ||
|
||
## Configurable height | ||
|
||
<Story id="basics-button--all-buttons" height="400px" /> |
30 changes: 30 additions & 0 deletions
30
lib/codemod/src/transforms/__testfixtures__/convert-mdx-to-module/story-refs.output.js
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,30 @@ | ||
import React from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Button } from '@storybook/react/demo'; | ||
|
||
export default { | ||
title: 'Addons|Docs/mdx', | ||
|
||
decorators: [ | ||
storyFn => ( | ||
<div | ||
style={{ | ||
backgroundColor: 'yellow', | ||
}} | ||
> | ||
{storyFn()} | ||
</div> | ||
), | ||
], | ||
|
||
parameters: { | ||
component: Button, | ||
notes: 'component notes', | ||
}, | ||
}; | ||
|
||
export const soloStory = () => <Button onClick={action('clicked')}>solo</Button>; | ||
|
||
soloStory.story = { | ||
name: 'solo story', | ||
}; |
1 change: 0 additions & 1 deletion
1
lib/codemod/src/transforms/__testfixtures__/convert-module-to-mdx/basic.output.js
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
1 change: 0 additions & 1 deletion
1
lib/codemod/src/transforms/__testfixtures__/convert-module-to-mdx/decorators.output.js
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
1 change: 0 additions & 1 deletion
1
lib/codemod/src/transforms/__testfixtures__/convert-module-to-mdx/exclude-stories.output.js
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
1 change: 0 additions & 1 deletion
1
lib/codemod/src/transforms/__testfixtures__/convert-module-to-mdx/parameters.output.js
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
1 change: 0 additions & 1 deletion
1
lib/codemod/src/transforms/__testfixtures__/convert-module-to-mdx/story-parameters.output.js
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
15 changes: 15 additions & 0 deletions
15
lib/codemod/src/transforms/__tests__/convert-mdx-to-module.test.js
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,15 @@ | ||
import { defineTest } from 'jscodeshift/dist/testUtils'; | ||
|
||
const testNames = [ | ||
'basic', | ||
'decorators', | ||
'parameters', | ||
'story-parameters', | ||
'exclude-stories', | ||
'story-refs', | ||
'plaintext', | ||
]; | ||
|
||
testNames.forEach(testName => { | ||
defineTest(__dirname, `convert-mdx-to-module`, null, `convert-mdx-to-module/${testName}`); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any markdown here just gets completely dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, yes. PR's welcome 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. do you think this is useful if we do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. We're going from a format that supports mixtures of longform documentation and code to one that does not. This completely solves the tedious task of translation in an automated fashion, and for now users will have to figure out themselves how they want to encode that documentation.
If we ever have a recommended way to encode longform docs in module format, we can try to encode that in the codemod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you could put markdown in the module format somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a prescription for that. Some users will put it in docgen comments, others in strings, others in
.md
files that get loaded in. When somebody has a good solution they want to push, they can upgrade this codemod accordingly.I personally think people should be using MDX for longform docs and not module format, and the purpose of this PR is to help people who try it and want to go back for whatever reason.