resolve fromPath

This commit is contained in:
SrGooglo 2023-03-03 21:47:55 +01:00
parent 132634a6e0
commit d9be128227

View File

@ -53,14 +53,22 @@ if (process.env.LOG_REQUESTS === "true") {
global.DEFAULT_MIDDLEWARES.push(require("morgan")(process.env.NODE_ENV === "development" ? "dev" : "combined"))
}
function registerBaseAliases(srcPath = "src") {
function registerBaseAliases(fromPath) {
if (typeof fromPath === "undefined") {
if (module.parent.filename.includes("dist")) {
fromPath = path.resolve(process.cwd(), "dist")
} else {
fromPath = path.resolve(process.cwd(), "src")
}
}
moduleAlias.addAliases({
"@controllers": path.resolve(process.cwd(), srcPath, "controllers"),
"@middlewares": path.resolve(process.cwd(), srcPath, "middlewares"),
"@models": path.resolve(process.cwd(), srcPath, "models"),
"@classes": path.resolve(process.cwd(), srcPath, "classes"),
"@lib": path.resolve(process.cwd(), srcPath, "lib"),
"@utils": path.resolve(process.cwd(), srcPath, "utils"),
"@controllers": path.resolve(fromPath, "controllers"),
"@middlewares": path.resolve(fromPath, "middlewares"),
"@models": path.resolve(fromPath, "models"),
"@classes": path.resolve(fromPath, "classes"),
"@lib": path.resolve(fromPath, "lib"),
"@utils": path.resolve(fromPath, "utils"),
})
}