1- /**
2- * @rlanz /bull-queue
3- *
4- * @license MIT
5- * @copyright Romain Lanz <[email protected] > 6- */
71import assert from "node:assert" ;
82import { SyntaxKind } from "ts-morph" ;
93
@@ -43,14 +37,20 @@ function addControllerImportIfNotExists(sourceFile: SourceFile) {
4337 ) ;
4438
4539 if ( ! hasControllerImport ) {
46- sourceFile . addVariableStatement ( {
47- declarations : [
48- {
49- name : "AuthController" ,
50- initializer : '() => import("#controllers/auth_controller")' ,
51- } ,
52- ] ,
53- } ) ;
40+ const importDeclarations = sourceFile . getImportDeclarations ( ) ;
41+
42+ if ( importDeclarations . length > 0 ) {
43+ const lastImport = importDeclarations [ importDeclarations . length - 1 ] ;
44+ sourceFile . insertStatements ( lastImport . getChildIndex ( ) + 1 , [
45+ "" , // Add empty line for spacing
46+ 'const AuthController = () => import("#controllers/auth_controller");' ,
47+ ] ) ;
48+ } else {
49+ // If no imports, add at the beginning (after any comments)
50+ sourceFile . insertStatements ( 0 , [
51+ 'const AuthController = () => import("#controllers/auth_controller");' ,
52+ ] ) ;
53+ }
5454 }
5555}
5656
@@ -113,7 +113,7 @@ export async function configure(command: Configure) {
113113 } ,
114114 leadingComment : "Variables for @solvro/auth" ,
115115 } ) ;
116-
116+ const action = command . logger . action ( "update start/routes.ts" ) ;
117117 const project = await codemods . getTsMorphProject ( ) ;
118118 assert ( project ) ;
119119
@@ -124,4 +124,6 @@ export async function configure(command: Configure) {
124124 addNewRoutes ( file ) ;
125125
126126 await file . save ( ) ;
127+
128+ action . succeeded ( ) ;
127129}
0 commit comments