Skip to content

Commit e706eff

Browse files
committed
fix: insert auth controller after imports
1 parent 6e5d4dc commit e706eff

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

packages/ally-solvro-auth/configure.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/**
2-
* @rlanz/bull-queue
3-
*
4-
* @license MIT
5-
* @copyright Romain Lanz <[email protected]>
6-
*/
71
import assert from "node:assert";
82
import { 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

Comments
 (0)