fix(utils): joiner config from medusa project (#7896)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { JoinerServiceConfigAlias, ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { join } from "path"
|
||||
import { dirname, join } from "path"
|
||||
import {
|
||||
MapToConfig,
|
||||
camelToSnakeCase,
|
||||
deduplicate,
|
||||
getCallerFilePath,
|
||||
MapToConfig,
|
||||
pluralize,
|
||||
upperCaseFirst,
|
||||
} from "../common"
|
||||
@@ -49,10 +49,17 @@ export function defineJoinerConfig(
|
||||
"serviceName" | "primaryKeys" | "linkableKeys" | "alias"
|
||||
>
|
||||
> {
|
||||
let basePath = getCallerFilePath()
|
||||
basePath = basePath.includes("dist")
|
||||
? basePath.split("dist")[0] + "dist"
|
||||
: basePath.split("src")[0] + "src"
|
||||
const fullPath = getCallerFilePath()
|
||||
const srcDir = fullPath.includes("dist") ? "dist" : "src"
|
||||
const splitPath = fullPath.split(srcDir)
|
||||
|
||||
let basePath = splitPath[0] + srcDir
|
||||
|
||||
const isMedusaProject = fullPath.includes(`${srcDir}/modules/`)
|
||||
if (isMedusaProject) {
|
||||
basePath = dirname(fullPath)
|
||||
}
|
||||
|
||||
basePath = join(basePath, "models")
|
||||
|
||||
const models = deduplicate(
|
||||
|
||||
@@ -2,9 +2,9 @@ import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
||||
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
import { upperCaseFirst } from "../../common"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { DmlEntity, toMikroORMEntity } from "../../dml"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
/**
|
||||
* Utility function to build a migration script that will revert the migrations.
|
||||
@@ -58,7 +58,7 @@ export function buildRevertMigrationScript({
|
||||
logger?.error(
|
||||
`${upperCaseFirst(
|
||||
moduleName
|
||||
)} module migration failed to run - Error: ${error}`
|
||||
)} module migration failed to run - Error: ${error.errros ?? error}`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
import { upperCaseFirst } from "../../common"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { DmlEntity, toMikroORMEntity } from "../../dml"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
/**
|
||||
* Utility function to build a migration script that will run the migrations.
|
||||
@@ -65,7 +65,7 @@ export function buildMigrationScript({ moduleName, models, pathToMigrations }) {
|
||||
logger.error(
|
||||
`${upperCaseFirst(
|
||||
moduleName
|
||||
)} module migration failed to run - Error: ${error}`
|
||||
)} module migration failed to run - Error: ${error.errros ?? error}`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user