chore(framework): Allow multiple source dir for subcribers loader (#8407)
* chore(framework): Allow multiple source dir for subcribers loader * re add log * add logs
This commit is contained in:
@@ -129,6 +129,7 @@ export class JobLoader {
|
|||||||
try {
|
try {
|
||||||
await access(sourcePath)
|
await access(sourcePath)
|
||||||
} catch {
|
} catch {
|
||||||
|
logger.info(`No job to load from ${sourcePath}. skipped.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export class LinkLoader {
|
|||||||
try {
|
try {
|
||||||
await access(sourcePath)
|
await access(sourcePath)
|
||||||
} catch {
|
} catch {
|
||||||
|
logger.info(`No link to load from ${sourcePath}. skipped.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class SubscriberLoader {
|
|||||||
* The base directory from which to scan for the subscribers
|
* The base directory from which to scan for the subscribers
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
#sourceDir: string
|
#sourceDir: string | string[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of file names to exclude from the subscriber scan
|
* The list of file names to exclude from the subscriber scan
|
||||||
@@ -46,7 +46,10 @@ export class SubscriberLoader {
|
|||||||
*/
|
*/
|
||||||
#subscriberDescriptors: Map<string, SubscriberModule<any>> = new Map()
|
#subscriberDescriptors: Map<string, SubscriberModule<any>> = new Map()
|
||||||
|
|
||||||
constructor(sourceDir: string, options: Record<string, unknown> = {}) {
|
constructor(
|
||||||
|
sourceDir: string | string[],
|
||||||
|
options: Record<string, unknown> = {}
|
||||||
|
) {
|
||||||
this.#sourceDir = sourceDir
|
this.#sourceDir = sourceDir
|
||||||
this.#pluginOptions = options
|
this.#pluginOptions = options
|
||||||
}
|
}
|
||||||
@@ -213,20 +216,21 @@ export class SubscriberLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
let hasSubscriberDir = false
|
const normalizeSourcePaths = Array.isArray(this.#sourceDir)
|
||||||
|
? this.#sourceDir
|
||||||
|
: [this.#sourceDir]
|
||||||
|
const promises = normalizeSourcePaths.map(async (sourcePath) => {
|
||||||
try {
|
try {
|
||||||
await access(this.#sourceDir)
|
await access(sourcePath)
|
||||||
hasSubscriberDir = true
|
} catch {
|
||||||
} catch (err) {
|
logger.info(`No subscribers to load from ${sourcePath}. skipped.`)
|
||||||
logger.debug(`No subscriber directory found in ${this.#sourceDir}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasSubscriberDir) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.createMap(this.#sourceDir)
|
return await this.createMap(sourcePath)
|
||||||
|
})
|
||||||
|
|
||||||
|
await promiseAll(promises)
|
||||||
|
|
||||||
for (const [
|
for (const [
|
||||||
fileName,
|
fileName,
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export class WorkflowLoader {
|
|||||||
try {
|
try {
|
||||||
await access(sourcePath)
|
await access(sourcePath)
|
||||||
} catch {
|
} catch {
|
||||||
|
logger.info(`No workflow to load from ${sourcePath}. skipped.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,23 +40,15 @@ const shouldLoadBackgroundProcessors = (configModule) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function subscribersLoader(plugins: PluginDetails[]) {
|
async function subscribersLoader(plugins: PluginDetails[]) {
|
||||||
|
const pluginSubscribersSourcePaths = [
|
||||||
/**
|
/**
|
||||||
* Load subscribers from the medusa/medusa package
|
* Load subscribers from the medusa/medusa package. Remove once the medusa core is converted to a plugin
|
||||||
*/
|
*/
|
||||||
await new SubscriberLoader(join(__dirname, "../subscribers")).load()
|
join(__dirname, "../subscribers"),
|
||||||
|
].concat(plugins.map((plugin) => join(plugin.resolve, "subscribers")))
|
||||||
|
|
||||||
// TODO: make it the same as the other loaders, taking an array of paths to load from
|
const subscriberLoader = new SubscriberLoader(pluginSubscribersSourcePaths)
|
||||||
/**
|
await subscriberLoader.load()
|
||||||
* Load subscribers from all the plugins.
|
|
||||||
*/
|
|
||||||
await Promise.all(
|
|
||||||
plugins.map(async (pluginDetails) => {
|
|
||||||
await new SubscriberLoader(
|
|
||||||
join(pluginDetails.resolve, "subscribers"),
|
|
||||||
pluginDetails.options
|
|
||||||
).load()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function jobsLoader(plugins: PluginDetails[]) {
|
async function jobsLoader(plugins: PluginDetails[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user