@@ -4,36 +4,35 @@ Automatic codemods to upgrade your styled-components code to newer versions.
44
55## Installation
66
7- ``` sh
8- npm install -g styled-components-codemods
9- ```
7+ Thanks to ` npx ` no installation is needed, just run the command below!
108
119## Usage
1210
13- ``` sh
14- Usage: styled-components-codemods [options] [command]
11+ ``` sh
12+ Usage: npx styled-components-codemods [options] [command]
1513
1614Options:
1715
18- -V, --version output the version number
19- -h, --help output usage information
16+ -V, --version output the version number
17+ -h, --help output usage information
2018
2119Commands:
2220
23- v4 [files...] Upgrade your code to styled-components v4 (codemods .extend)
21+ v4 [...files] Run all v4 codemods
22+ v4-extendToStyled [...files] Run just the extendToStyled codemod
23+ v4-injectGlobalToCreateGlobalStyle [...files] Run just the injectGlobalToCreateGlobalStyle codemod
2424
2525Examples:
2626
27- $ styled-components-codemods v4 src/components/Box.js src/components/Button.js
27+ $ styled-components-codemods v4-extendToStyled src/components/Box.js src/components/Button.js
2828 $ styled-components-codemods v4 src/** /* .js (this will only work if your terminal expands globs)
2929` ` `
3030
3131# ## Codemods
3232
33-
3433# ### v4
3534
36- In version 4 of ` styled-components` the ` Component.extends` API will be removed in favor of only using ` styled(Component)` . This codemod replaces all ` .extends` calls to equivalent ` styled()` calls instead.
35+ In version 4 of ` styled-components` the ` Component.extends` API will be removed in favor of only using ` styled(Component)` . This codemod replaces all ` .extends` calls to equivalent ` styled()` calls instead. Furthermore, the injectGlobal API has been upgraded to slot into React ' s lifecycle more naturally. It refactors all `injectGlobal` calls, and warns you where they are, so you can export them and include them when rendering.
3736
3837##### Limitations
3938
@@ -47,37 +46,42 @@ There is no way to distinguish whether `.extend` identifier is related to `style
4746
4847 <summary>Code Before</summary>
4948
50-
5149```javascript
52- StyledComponent.extend` `
50+ StyledComponent.extend``;
5351
54- StyledComponent.extend` color: red; `
52+ StyledComponent.extend`
53+ color: red;
54+ `;
5555
56- StyledComponent.extend({ color: " red" })
56+ StyledComponent.extend({ color: "red" });
5757
58- StyledComponent.extend
58+ StyledComponent.extend;
5959
60- StyledComponent.extend` ` .extend
60+ StyledComponent.extend``.extend;
6161
62- StyledComponent.extend({ color: red }).extend
62+ StyledComponent.extend({ color: red }).extend;
6363
64- styled.div` ` .extend` `
64+ styled.div``.extend``;
6565
66- styled.div` color: red; ` .extend` color: blue; `
66+ styled.div`
67+ color: red;
68+ `.extend`color: blue;`;
6769
68- styled.div({ color: " red" }).extend({ color: " blue" })
70+ styled.div({ color: "red" }).extend({ color: "blue" });
6971
70- StyledComponent.withComponent(' div' ).extend` `
72+ StyledComponent.withComponent(" div" ).extend``;
7173
72- StyledComponent.withComponent(' div' ).extend` color: red; `
74+ StyledComponent.withComponent(" div" ).extend`color: red;`;
7375
74- StyledComponent.withComponent(' div' ).extend ()
76+ StyledComponent.withComponent(" div" ).extend();
7577
76- StyledComponent.withComponent(' div' ).extend({ color: red })
78+ StyledComponent.withComponent(" div" ).extend({ color: red });
7779
78- StyledComponent.extend().extend().extend ().extend` `
80+ StyledComponent.extend()
81+ .extend()
82+ .extend().extend``;
7983
80- StyledComponent.extend``.extend ().extend` ` .extend` `
84+ StyledComponent.extend``.extend().extend``.extend``;
8185```
8286
8387</details>
@@ -87,49 +91,47 @@ StyledComponent.extend``.extend().extend``.extend``
8791 <summary>Code after</summary>
8892
8993```javascript
90- import styled, { css } from ' styled-components'
94+ import styled, { css } from " styled-components";
9195
92- styled(StyledComponent)` `
96+ styled(StyledComponent)``;
9397
9498styled(StyledComponent)`
9599 color: red;
96- `
100+ `;
97101
98- styled(StyledComponent)({ color: ' red' })
102+ styled(StyledComponent)({ color: " red" });
99103
100- styled(StyledComponent)
104+ styled(StyledComponent);
101105
102- styled(styled(StyledComponent)` ` )
106+ styled(styled(StyledComponent)``);
103107
104- styled(styled(StyledComponent)({ color: red }))
108+ styled(styled(StyledComponent)({ color: red }));
105109
106- styled(styled.div` ` )` `
110+ styled(styled.div``)``;
107111
108112styled(
109113 styled.div`
110114 color: red;
111115 `
112116)`
113117 color: blue;
114- `
118+ `;
115119
116- styled(styled.div({ color: ' red' }))({ color: ' blue' })
120+ styled(styled.div({ color: " red" }))({ color: " blue" });
117121
118- styled(StyledComponent.withComponent(' div' ))` `
122+ styled(StyledComponent.withComponent(" div" ))``;
119123
120- styled(StyledComponent.withComponent(' div' ))`
124+ styled(StyledComponent.withComponent(" div" ))`
121125 color: red;
122- `
126+ `;
123127
124- styled(StyledComponent.withComponent(' div' )) ()
128+ styled(StyledComponent.withComponent(" div" ))();
125129
126- styled(StyledComponent.withComponent(' div' ))({ color: red })
130+ styled(StyledComponent.withComponent(" div" ))({ color: red });
127131
128- styled(styled(styled(styled(StyledComponent)())()) ())` `
132+ styled(styled(styled(styled(StyledComponent)())())())``;
129133
130- styled(styled(styled(styled(StyledComponent)``) ())` ` )` `
134+ styled(styled(styled(styled(StyledComponent)``)())``)``;
131135```
132136
133137</details>
134-
135-
0 commit comments