feat(admin-bundler,admin-vite-plugin,medusa): Add support for loading Admin Extensions from plugins (#10869)
Should not be merged before https://github.com/medusajs/medusa/pull/10895 **What** - Introduces a new `plugin` command to `admin-bundler`, currently not used anywhere but will be called from `medusa build:plugin` - Discovers plugins with extensions and add passes the to `admin-vite-plugin`. - Updates `admin-vite-plugin` so its able to read built admin extensions. Resolves CMRC-830, CMRC-839
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
import { AdminOptions, ConfigModule } from "@medusajs/framework/types"
|
||||
import {
|
||||
AdminOptions,
|
||||
ConfigModule,
|
||||
PluginDetails,
|
||||
} from "@medusajs/framework/types"
|
||||
import { Express } from "express"
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
@@ -9,6 +13,7 @@ type Options = {
|
||||
app: Express
|
||||
configModule: ConfigModule
|
||||
rootDirectory: string
|
||||
plugins: PluginDetails[]
|
||||
}
|
||||
|
||||
type IntializedOptions = Required<Pick<AdminOptions, "path" | "disable">> &
|
||||
@@ -23,16 +28,18 @@ export default async function adminLoader({
|
||||
app,
|
||||
configModule,
|
||||
rootDirectory,
|
||||
plugins,
|
||||
}: Options) {
|
||||
const { admin } = configModule
|
||||
|
||||
const sources: string[] = []
|
||||
|
||||
const projectSource = path.join(rootDirectory, "src", "admin")
|
||||
for (const plugin of plugins) {
|
||||
const pluginSource = path.join(plugin.resolve, "admin")
|
||||
|
||||
// check if the projectSource exists
|
||||
if (fs.existsSync(projectSource)) {
|
||||
sources.push(projectSource)
|
||||
if (fs.existsSync(pluginSource)) {
|
||||
sources.push(pluginSource)
|
||||
}
|
||||
}
|
||||
|
||||
const adminOptions: IntializedOptions = {
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
import { container, MedusaAppLoader } from "@medusajs/framework"
|
||||
import { configLoader } from "@medusajs/framework/config"
|
||||
import { pgConnectionLoader } from "@medusajs/framework/database"
|
||||
import { featureFlagsLoader } from "@medusajs/framework/feature-flags"
|
||||
import { expressLoader } from "@medusajs/framework/http"
|
||||
import { JobLoader } from "@medusajs/framework/jobs"
|
||||
import { LinkLoader } from "@medusajs/framework/links"
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
import { SubscriberLoader } from "@medusajs/framework/subscribers"
|
||||
import {
|
||||
ConfigModule,
|
||||
LoadedModule,
|
||||
@@ -10,6 +19,7 @@ import {
|
||||
mergePluginModules,
|
||||
promiseAll,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { WorkflowLoader } from "@medusajs/framework/workflows"
|
||||
import { asValue } from "awilix"
|
||||
import { Express, NextFunction, Request, Response } from "express"
|
||||
import { join } from "path"
|
||||
@@ -17,16 +27,6 @@ import requestIp from "request-ip"
|
||||
import { v4 } from "uuid"
|
||||
import adminLoader from "./admin"
|
||||
import apiLoader from "./api"
|
||||
import { configLoader } from "@medusajs/framework/config"
|
||||
import { expressLoader } from "@medusajs/framework/http"
|
||||
import { JobLoader } from "@medusajs/framework/jobs"
|
||||
import { LinkLoader } from "@medusajs/framework/links"
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
import { container, MedusaAppLoader } from "@medusajs/framework"
|
||||
import { pgConnectionLoader } from "@medusajs/framework/database"
|
||||
import { SubscriberLoader } from "@medusajs/framework/subscribers"
|
||||
import { WorkflowLoader } from "@medusajs/framework/workflows"
|
||||
import { featureFlagsLoader } from "@medusajs/framework/feature-flags"
|
||||
import { getResolvedPlugins } from "./helpers/resolve-plugins"
|
||||
|
||||
type Options = {
|
||||
@@ -107,7 +107,7 @@ async function loadEntrypoints(
|
||||
next()
|
||||
})
|
||||
|
||||
await adminLoader({ app: expressApp, configModule, rootDirectory })
|
||||
await adminLoader({ app: expressApp, configModule, rootDirectory, plugins })
|
||||
await apiLoader({
|
||||
container,
|
||||
plugins,
|
||||
|
||||
Reference in New Issue
Block a user