4

I'm updating from Material-UI 0.x to 1.0.

The docs for migration-helper say to run:

 jscodeshift -t <codemod-script> <path>. 

I've never used jscodeshift before, and I've never seen the notation before, so I would like to get some advice on how to use this. :) Googling jscodeshift codemod-script brings up nothing relevant.

What does codemod-script need to be?

VikR
  • 4,818
  • 8
  • 51
  • 96

1 Answers1

6

It took me a bit to figure this out. After you've installed jscodeshift and the material-ui codemods, the command should be formatted as follows:

jscodeshift -t <the file path of the specific code mod file> <the location of the files you want to process>

jscodeshift -t ./node_modules/@material-ui/codemod/lib/v1.0.0/svg-icon-imports.js ./src/

I also use the extension jsx for my files so I had to add the --extensions flag:

jscodeshift -t ./node_modules/@material-ui/codemod/lib/v1.0.0/svg-icon-imports.js ./src/ --extensions jsx

Michael Cook
  • 1,676
  • 2
  • 26
  • 47
  • Very good. Do I run it one time for every m-ui file I import, e.g `material-ui/List`, `material-ui/Avatar`, etc.? – VikR Sep 02 '18 at 03:59
  • All at once from what I can tell, but I just got it running myself, so I'm not 100% sure. – Michael Cook Sep 03 '18 at 19:18
  • The example command in your post, `jscodeshift -t ./node_modules/@material-ui/codemod/lib/v1.0.0/svg-icon-imports.js ./src/ --extensions jsx`, seems to just be for one m-ui file, `svg-icon-imports.js ./`. That's why I had the impression I would run it one time for every m-ui file. Am I missing something? Thanks in advance for your thoughts. – VikR Sep 03 '18 at 22:25
  • Oh yes, I could only get it to run one code-mod at a time. Honestly, I found them rather buggy and not a whole lot of help. I ran them, but I'm still doing 90% of the work by hand. – Michael Cook Sep 04 '18 at 01:14