GitXplorerGitXplorer
j

ts-morphin-migration

public
0 stars
1 forks
15 issues

Commits

List of commits on branch master.
Unverified
47b3e21ad51cc67db03f38059e2b866be7cb7b9d

minor fixes

jjoschect committed 5 years ago
Unverified
2d05e8c0822cd72fa77592e6b85670a7fe9160f7

minor fixes

jjoschect committed 5 years ago
Unverified
33a3896a753c53ffb4241baa4b2affc8a4b2f940

remove parts of command test that aren't used

jjoschect committed 5 years ago
Unverified
7ce841211365d873f4c4d56ffa8210af0d317508

update command

jjoschect committed 5 years ago
Unverified
d9c77d78325d8b88d04d9103d5d7bcacc02184ee

many improvements, actually working

jjoschect committed 5 years ago
Unverified
a50c2cde4098c7d5a82dd8efcb7761f8696a2c6c

update package and readmen

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
     }