Documentation
    Preparing search index...

    This class is responsible for transforming AdonisJS project code, including updating middleware, environment validations, and other code generation tasks.

    The CodeTransformer provides methods for modifying various AdonisJS configuration files and code structures using AST manipulation through ts-morph. It can update middleware stacks, add environment validations, register plugins, and modify RC file configurations.

    const transformer = new CodeTransformer(cwd)
    await transformer.addMiddlewareToStack('server', [{
    path: '#middleware/cors_middleware',
    position: 'before'
    }])
    Index

    Constructors

    Properties

    installPackage: (
        names: string | string[],
        options?: InstallPackageOptions,
    ) => Promise<Output> = installPackage

    Utility function for installing packages

    detectPackageManager: (cwd?: string) => Promise<null | Agent> = detectPackageManager

    Utility function for detecting the package manager

    project: Project

    The TsMorph project instance for AST manipulation

    Methods

    • Define new middlewares inside the start/kernel.ts file

      This function is highly based on some assumptions and will not work if you significantly tweaked your start/kernel.ts file.

      Parameters

      • stack: "named" | "server" | "router"

        The middleware stack to add to ('server', 'router', or 'named')

      • middleware: MiddlewareNode[]

        Array of middleware entries to add

      Returns Promise<void>

    • Add a new Japa plugin in the tests/bootstrap.ts file

      Parameters

      • pluginCall: string

        The plugin function call to add

      • importDeclarations: { isNamed: boolean; module: string; identifier: string }[]

        Import declarations needed for the plugin

      Returns Promise<void>

    • Add a new Vite plugin to the vite.config.ts file

      Parameters

      • pluginCall: string

        The plugin function call to add

      • importDeclarations: { isNamed: boolean; module: string; identifier: string }[]

        Import declarations needed for the plugin

      Returns Promise<void>