Skip to content

Commit

Permalink
Add support for typescript commands in codemod readme
Browse files Browse the repository at this point in the history
  • Loading branch information
StuffByLiang committed Apr 6, 2021
1 parent 013b3d9 commit c8b5cb0
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/material-ui-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ APIs.

## Setup & Run

- `npm install -D @material-ui/codemod`
- `npx jscodeshift -t <codemod-script> <path>`
- Use the `-d` option for a dry-run and use `-p` to print the output
- `npm install -D @material-ui/codemod@next`
- `npx jscodeshift -t <url-to-codemod-script> <path>`
- Applys the transform script specified in `<url-to-codemod-script>` recursively to `<path>`
- Use the `-d` option for a dry-run and use `-p` to print the output
for comparison
- use the `--extensions tsx --parser tsx` options to convert Typescript sources

## Included Scripts

Expand All @@ -32,7 +34,7 @@ The diff should look like this:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v5.0.0/box-sx-prop.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v5.0.0/box-sx-prop.js ./src
```

#### `moved-lab-modules`
Expand All @@ -52,7 +54,7 @@ or
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v5.0.0/moved-lab-modules.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v5.0.0/moved-lab-modules.js ./src
```

#### `textfield-variant-prop`
Expand All @@ -70,7 +72,7 @@ The diff should look like this:
This codemod is non-idempotent (`variant="standard"` would be added on a subsequent run, where `variant="outlined"` was removed), so should only be run once against any particular codebase.

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v5.0.0/textfield-variant-prop.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v5.0.0/textfield-variant-prop.js ./src
```

### v4.0.0
Expand All @@ -86,7 +88,7 @@ The diff should look like this:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v4.0.0/theme-spacing-api.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v4.0.0/theme-spacing-api.js ./src
```

This codemod tries to perform a basic expression simplification which can be improved for expressions that use more than one operation.
Expand All @@ -111,7 +113,7 @@ Converts all `@material-ui/core` imports more than 1 level deep to the optimal f
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v4.0.0/optimal-imports.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v4.0.0/optimal-imports.js ./src
```

Head to https://material-ui.com/guides/minimizing-bundle-size/ to understand when it's useful.
Expand All @@ -127,7 +129,7 @@ Converts all `@material-ui/core` submodule imports to the root module:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v4.0.0/top-level-imports.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v4.0.0/top-level-imports.js ./src
```

Head to https://material-ui.com/guides/minimizing-bundle-size/ to understand when it's useful.
Expand All @@ -146,7 +148,7 @@ The diff should look like this:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v1.0.0/import-path.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v1.0.0/import-path.js ./src
```

**Notice**: if you are migrating from pre-v1.0, and your imports use `material-ui`, you will need to manually find and replace all references to `material-ui` in your code to `@material-ui/core`. E.g.:
Expand All @@ -171,7 +173,7 @@ The diff should look like this:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v1.0.0/color-imports.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v1.0.0/color-imports.js ./src
```

**additional options**
Expand All @@ -193,7 +195,7 @@ The diff should look like this:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v1.0.0/svg-icon-imports.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v1.0.0/svg-icon-imports.js ./src
```

### v0.15.0
Expand All @@ -215,7 +217,7 @@ The diff should look like this:
```

```sh
find src -name '*.js' -print | xargs npx jscodeshift -t node_modules/@material-ui/codemod/v0.15.0/import-path.js
npx jscodeshift --extensions js,ts,jsx,tsx --parser tsx -t node_modules/@material-ui/codemod/v0.15.0/import-path.js ./src
```

### Recast Options
Expand Down

0 comments on commit c8b5cb0

Please sign in to comment.