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