core icon indicating copy to clipboard operation
core copied to clipboard

feat: add getTsMorphProject method

Open Julien-R44 opened this issue 1 year ago • 0 comments

PR is targetting #4412 and depends on https://github.com/adonisjs/assembler/pull/74


Two things :

  • add a getTsMorphProject() method on Codemods class. so that users can make their own codemods as explained in https://github.com/adonisjs/assembler/pull/74

    export async function configure(command: Configure) {
      const codemods = await command.createCodemods()
     const project = await codemods.getTsMorphProject()
    
    // can do whatever I want
     project.getSourceFileOrThrow('file.ts').addImportDeclaration({
       moduleSpecifier: 'ts-morph',
       namedImports: ['Project'],
     })
    }
    
  • Refactoring the Codemods class so as to create just one instance of ts-morph and CodeTransformer. Creating an instance of ts-morph is a costly operation

Julien-R44 avatar Feb 17 '24 20:02 Julien-R44