Template repository for Typescript jscodeshift transformers. It's based on the official jscodeshift conventions to build transformers. This template includes tests and a debug config for VS Code too.
Be careful when using codemods and always check the transformed code. Also remember that not every code migration can be easily 100% automated.
Install dependencies:
$ npm i
Run tests:
$ npm test
Install jscodeshift:
$ npm i -g jscodeshift
Run a codemod for Typescript files:
$ jscodeshift --parser=ts -t <path-to-codemod> <file-path-or-pattern>
An example codemod. It replaces all identifier names with a new name. This codemod showcases Typescript code, custom options and change detection to avoid writing ASTs to files if there are no changes.
Example:
command
jscodeshift -t ./src/example.ts <file> --parser=ts --newName=hello
input code
output code
Options:
- newName (string)
The new name of every identifier in the source code. Set by default to
'hello'
.