chore(framework): Move and improve workflows loader (#8363)

**What**
Refactoring Workflows loader and move

FIXES FRMW-2627
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2024-07-31 14:46:04 +00:00
1 parent 22a629670b
commit 56602d215b
15 files changed
+192 -42

No files matched your search

@@ -1,22 +0,0 @@
import { glob } from "glob"
import { PluginDetails } from "@medusajs/types"
/**
* import files from the workflows directory to run the registration of the wofklows
* @param pluginDetails
*/
export async function registerWorkflows(
plugins: PluginDetails[]
): Promise<void> {
await Promise.all(
plugins.map(async (pluginDetails) => {
const files = glob.sync(
`${pluginDetails.resolve}/workflows/*.{ts,js,mjs,mts}`,
{
ignore: ["**/*.d.ts", "**/*.map"],
}
)
return Promise.all(files.map(async (file) => import(file)))
})
)
}
+9 -9
View File
@@ -13,13 +13,13 @@ import {
container,
expressLoader,
featureFlagsLoader,
LinkLoader,
JobLoader,
LinkLoader,
logger,
pgConnectionLoader,
SubscriberLoader,
WorkflowLoader,
} from "@medusajs/framework"
import { registerWorkflows } from "./helpers/register-workflows"
import { getResolvedPlugins } from "./helpers/resolve-plugins"
import loadMedusaApp from "./medusa-app"
@@ -45,6 +45,7 @@ async function subscribersLoader(plugins: PluginDetails[]) {
*/
await new SubscriberLoader(join(__dirname, "../subscribers")).load()
// TODO: make it the same as the other loaders, taking an array of paths to load from
/**
* Load subscribers from all the plugins.
*/
@@ -121,15 +122,11 @@ async function loadEntrypoints(
export async function initializeContainer(
rootDirectory: string
): Promise<MedusaContainer> {
const configModule = configLoader(rootDirectory, "medusa-config.js")
const featureFlagRouter = await featureFlagsLoader(
join(__dirname, "feature-flags")
)
configLoader(rootDirectory, "medusa-config.js")
await featureFlagsLoader(join(__dirname, "feature-flags"))
container.register({
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
[ContainerRegistrationKeys.FEATURE_FLAG_ROUTER]: asValue(featureFlagRouter),
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
[ContainerRegistrationKeys.REMOTE_QUERY]: asValue(null),
})
@@ -164,7 +161,10 @@ export default async ({
container,
})
await registerWorkflows(plugins)
const workflowsSourcePaths = plugins.map((p) => join(p.resolve, "workflows"))
const workflowLoader = new WorkflowLoader(workflowsSourcePaths)
await workflowLoader.load()
const entrypointsShutdown = await loadEntrypoints(
plugins,
container,