|
| 1 | +# @react-md/codemod |
| 2 | + |
| 3 | +This repository contains a collection of codemod scripts for use with |
| 4 | +[JSCodeshift](https://github.com/facebook/jscodeshift) that help update ReactMD |
| 5 | +APIs. |
| 6 | + |
| 7 | +> Note: If you use [prettier](https://prettier.io/), you will most likely need |
| 8 | +> to re-format your files after running a codemod. |
| 9 | +
|
| 10 | +<!-- docs --> |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +```sh |
| 15 | +Usage: npx @react-md/codemod [options] [command] |
| 16 | + |
| 17 | +Run a codemod script to update to the latest version of ReactMD. |
| 18 | + |
| 19 | +Running this script without any options or commands will start an interactive wizard. |
| 20 | + |
| 21 | + |
| 22 | +Options: |
| 23 | + -h, --help display help for command |
| 24 | + |
| 25 | +Commands: |
| 26 | + v3-to-v4/preset [options] [files...] |
| 27 | + v3-to-v4/rename-text-to-typography [options] [files...] |
| 28 | + v3-to-v4/scale-transition-props [options] [files...] |
| 29 | +``` |
| 30 | + |
| 31 | +### Transformations |
| 32 | + |
| 33 | +### `v3-to-v4/preset` |
| 34 | + |
| 35 | +```sh |
| 36 | +Usage: npx @react-md/codemod v3-to-v4/preset [options] [files...] |
| 37 | + |
| 38 | +Arguments: |
| 39 | + files An optional glob or folder path to transform |
| 40 | + (default: ".") |
| 41 | + |
| 42 | +Options: |
| 43 | + -d, --dry Dry run (no changes are made to files) (default: |
| 44 | + false) |
| 45 | + -p, --print Print transformed files to your terminal |
| 46 | + (default: false) |
| 47 | + --parser <parser> The file parser to use. (choices: "babel", |
| 48 | + "tsx", "", default: "") |
| 49 | + --jscodeshift <jscodeshift> (Advanced) Pass options directly to jscodeshift |
| 50 | + (default: "") |
| 51 | + -h, --help display help for command |
| 52 | +``` |
| 53 | + |
| 54 | +### `v3-to-v4/rename-text-to-typography` |
| 55 | + |
| 56 | +#### Changes |
| 57 | + |
| 58 | +```diff |
| 59 | + import { |
| 60 | +- Text, |
| 61 | +- TextProps, |
| 62 | +- TextTypes, |
| 63 | +- TextRenderFunction, |
| 64 | +- TextElement, |
| 65 | ++ Typography, |
| 66 | ++ TypographyProps, |
| 67 | ++ TypographyType, |
| 68 | ++ TypographyRenderFunction, |
| 69 | ++ TypographyHTMLElement, |
| 70 | + TextContainer, |
| 71 | + } from "@react-md/typography"; |
| 72 | + |
| 73 | +-const renderer: TextRenderFunction = ({ className }) => ( |
| 74 | ++const renderer: TypographyRenderFunction = ({ className }) => ( |
| 75 | + <div className={className} /> |
| 76 | + ); |
| 77 | + |
| 78 | +-const types: TextTypes[] = [ |
| 79 | ++const types: TypographyType[] = [ |
| 80 | + "headline-1", |
| 81 | + "headline-2", |
| 82 | + "headline-3", |
| 83 | +@@ -27,17 +27,15 @@ const types: TextTypes[] = [ |
| 84 | + "button", |
| 85 | + ]; |
| 86 | + |
| 87 | +-const props: TextProps = {}; |
| 88 | +-let element: TextElement; |
| 89 | ++const props: TypographyProps = {}; |
| 90 | ++let element: TypographyHTMLElement; |
| 91 | + |
| 92 | + export default function Example() { |
| 93 | +- return ( |
| 94 | +- <> |
| 95 | +- <Text>Hello</Text> |
| 96 | ++ return <> |
| 97 | ++ <Typography>Hello</Typography> |
| 98 | + <TextContainer> |
| 99 | +- <Text>World!</Text> |
| 100 | +- <Text type="headline-1">Headline</Text> |
| 101 | ++ <Typography>World!</Typography> |
| 102 | ++ <Typography type="headline-1">Headline</Typography> |
| 103 | + </TextContainer> |
| 104 | +- </> |
| 105 | +- ); |
| 106 | ++ </>; |
| 107 | + } |
| 108 | +, |
| 109 | +``` |
| 110 | + |
| 111 | +```sh |
| 112 | +Usage: npx @react-md/codemod v3-to-v4/rename-text-to-typography [options] [files...] |
| 113 | + |
| 114 | +Arguments: |
| 115 | + files An optional glob or folder path to transform |
| 116 | + (default: ".") |
| 117 | + |
| 118 | +Options: |
| 119 | + -d, --dry Dry run (no changes are made to files) (default: |
| 120 | + false) |
| 121 | + -p, --print Print transformed files to your terminal |
| 122 | + (default: false) |
| 123 | + --parser <parser> The file parser to use. (choices: "babel", |
| 124 | + "tsx", "", default: "") |
| 125 | + --jscodeshift <jscodeshift> (Advanced) Pass options directly to jscodeshift |
| 126 | + (default: "") |
| 127 | + -h, --help display help for command |
| 128 | +``` |
| 129 | + |
| 130 | +### `v3-to-v4/scale-transition-props` |
| 131 | + |
| 132 | +#### Changes |
| 133 | + |
| 134 | +```diff |
| 135 | + |
| 136 | + export default function Example() { |
| 137 | + const [visible, setVisible] = useState(false); |
| 138 | +- return ( |
| 139 | +- <> |
| 140 | ++ return <> |
| 141 | + <button type="button" onClick={() => setVisible((p) => !p)}> |
| 142 | + Toggle |
| 143 | + </button> |
| 144 | +- <ScaleTransition visible={visible}> |
| 145 | ++ <ScaleTransition transitionIn={visible}> |
| 146 | + <div>Something</div> |
| 147 | + </ScaleTransition> |
| 148 | +- </> |
| 149 | +- ); |
| 150 | ++ </>; |
| 151 | + } |
| 152 | +, |
| 153 | +``` |
| 154 | + |
| 155 | +```sh |
| 156 | +Usage: npx @react-md/codemod v3-to-v4/scale-transition-props [options] [files...] |
| 157 | + |
| 158 | +Arguments: |
| 159 | + files An optional glob or folder path to transform |
| 160 | + (default: ".") |
| 161 | + |
| 162 | +Options: |
| 163 | + -d, --dry Dry run (no changes are made to files) (default: |
| 164 | + false) |
| 165 | + -p, --print Print transformed files to your terminal |
| 166 | + (default: false) |
| 167 | + --parser <parser> The file parser to use. (choices: "babel", |
| 168 | + "tsx", "", default: "") |
| 169 | + --jscodeshift <jscodeshift> (Advanced) Pass options directly to jscodeshift |
| 170 | + (default: "") |
| 171 | + -h, --help display help for command |
| 172 | +``` |
0 commit comments