Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run jscodeshift transform on all files?

Tags:

jscodeshift

I am creating a transform that will replace all instances of:

templateUrl: 'some/url/to/some.html'

with

template: require('some/url/to/some.html')

I am doing this because I am changing the way that our AngularJS code brings in their templates. I am going to make them all use the webpack string loader.

I have gotten the transform to work. But now I have no idea how to run it against all of the files in my project. I can't see in the documentation how to run this against all of the .js files in my project. To run my transform, I currently type:

jscodeshift ./folder/myComponent.js -t ./tools/codemodes/template.js -d -p

This command will run my transform against the myComponent.js file, but I want it to be run against all of the .js files in my project. What do I need to change with my current command to make it select all .js files, and run the transform against all of them?

like image 214
frosty Avatar asked Mar 10 '23 07:03

frosty


1 Answers

If you want to run a transform against all files in a directory, you just enter the directory path, instead of a file path. In the example above, do the following:

jscodeshift ./folder -t ./tools/codemod/templates.js -d -p

That will run the transform against all of your nested js files.

like image 113
frosty Avatar answered Jun 14 '23 16:06

frosty