GitXplorerGitXplorer
j

ts-morphin-migration

public
0 stars
1 forks
15 issues

Commits

List of commits on branch master.
Unverified
5f9cb5fb5ad5a9aae128fd2b9025048d1b50e652

add files

jjoschect committed 5 years ago
Unverified
6eea7a66eaa2ad97b3a757bfa8a166506f364acd

rename and move tests for clarity

jjoschect committed 5 years ago
Unverified
f72fb5c91df602447259ceb2b84c834cfe7eb1ac

Renamed import repath codemod

jjoschect committed 5 years ago
Unverified
fc35903a631a621cfb10f0e9970458364bca4a42

add new utiles rename

jjoschect committed 5 years ago
Unverified
702508cd1907158ec6cef5ee9d5a8b8d04952a91

renamed and repathed utils

jjoschect committed 5 years ago
Unverified
7a6838bdebead8f40a5e6272d3984c7a4c0f1bd0

add coin test, refactor a little

jjoschect committed 5 years ago

README

The README file for this repository.

ts-morphin-migration

ts-morphin-migration is a package created and managed with the create-just utility.

Next Steps

Now that you have created this repository, go ahead and run the following to get started:

yarn
yarn start-test

Executing a codemod (Prototype)

Add your codemods to the ./src/index.ts

Run

yarn build

To build the migration.js file

In the command line, cd to the project that you want to change and run npx <path to ts-morphin-migration>\bin\migration.js <source folder to run migrations on>

Todos

  • Improve command line calling of the migration.js file.
  • Target the tsconfig.json file rather than having users enter their own path
  • Write a flag utility that will enable devs to note when a part of a file needs to be changed, but cannot be done via codemod.
  • Implement a command that will execute all listed codemods on a single file.
    • Will need to think of a way to specify the order. Maybe something like tasks in Just.

Notes

ts-morph:

  • ts-morph does most of the heavy lifting. Don't be afraid to use it directly rather than trying to abstract into a utility.
  • One of the most useful types of the syntax tree to get is the SyntaxKind.block it is the equivalent of the { stuff } that is located in a function declaration and is where a lot of code lives.
  • You can only access JSX props on syntax kinds of SyntaxKind.JSXOpeningElement and SyntaxKind.JSXSelfClosingElement
  • getChildIndex returns the child index respective to the immediate parent. It resets each level. So consider the following:
         function foo() {
             const childIndex0 = "some other value";
             const childIndex1 = "some value";
             return childIndex2;
         }
    

And then consider

     function foo() {
         const childIndex0 = "some other value";
         const childIndex1 = "some value";
         const nestedFunctionChildIndex2 = () => {
             const childIndex0; // childindex is now 0
         }
         return childIndex3
     }