**What** Scafold the fulfillment module basic structure **Bonus** Simplified module scaffolding with new factories and less directories to manage - mikro orm connection loader factory - initialize factory FIXES CORE-1709 FIXES CORE-1710
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import {
|
|
ExternalModuleDeclaration,
|
|
InternalModuleDeclaration,
|
|
ModuleExports,
|
|
ModuleServiceInitializeCustomDataLayerOptions,
|
|
ModuleServiceInitializeOptions,
|
|
} from "@medusajs/types"
|
|
import { MODULE_PACKAGE_NAMES } from "../definitions"
|
|
import { MedusaModule } from "../medusa-module"
|
|
|
|
/**
|
|
* Generate a initialize module factory that is exported by the module to be initialized manually
|
|
*
|
|
* @param moduleName
|
|
* @param moduleDefinition
|
|
*/
|
|
export function initializeFactory<T>({
|
|
moduleName,
|
|
moduleDefinition,
|
|
}: {
|
|
moduleName: string
|
|
moduleDefinition: ModuleExports
|
|
}) {
|
|
return async (
|
|
options?:
|
|
| ModuleServiceInitializeOptions
|
|
| ModuleServiceInitializeCustomDataLayerOptions
|
|
| ExternalModuleDeclaration
|
|
| InternalModuleDeclaration,
|
|
injectedDependencies?: any
|
|
) => {
|
|
const loaded = await MedusaModule.bootstrap<T>({
|
|
moduleKey: moduleName,
|
|
defaultPath: MODULE_PACKAGE_NAMES[moduleName],
|
|
declaration: options as
|
|
| InternalModuleDeclaration
|
|
| ExternalModuleDeclaration,
|
|
injectedDependencies,
|
|
moduleExports: moduleDefinition,
|
|
})
|
|
|
|
return loaded[moduleName] as T
|
|
}
|
|
}
|