feat(admin, admin-ui, medusa-js, medusa-react, medusa): Support Admin Extensions (#4761)
Co-authored-by: Rares Stefan <948623+StephixOne@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
26c78bbc03
commit
f1a05f4725
42
packages/admin/src/utils/get-plugin-paths.ts
Normal file
42
packages/admin/src/utils/get-plugin-paths.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { logger } from "@medusajs/admin-ui"
|
||||
import type { ConfigModule } from "@medusajs/medusa"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
import path from "path"
|
||||
|
||||
function hasEnabledUI(options: Record<string, unknown>) {
|
||||
return "enableUI" in options && options.enableUI === true
|
||||
}
|
||||
|
||||
export async function getPluginPaths() {
|
||||
const { configModule, error } = getConfigFile<ConfigModule>(
|
||||
path.resolve(process.cwd()),
|
||||
"medusa-config.js"
|
||||
)
|
||||
|
||||
if (error) {
|
||||
logger.panic("Error loading `medusa-config.js`")
|
||||
}
|
||||
|
||||
const plugins = configModule.plugins || []
|
||||
|
||||
const paths: string[] = []
|
||||
|
||||
for (const p of plugins) {
|
||||
if (typeof p === "string") {
|
||||
continue
|
||||
} else {
|
||||
const options = p.options || {}
|
||||
|
||||
/**
|
||||
* While the feature is in beta, we only want to load plugins that have
|
||||
* enabled the UI explicitly. In the future, we will flip this check so
|
||||
* we only exclude plugins that have set `enableUI` to false.
|
||||
*/
|
||||
if (hasEnabledUI(options)) {
|
||||
paths.push(p.resolve)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
Reference in New Issue
Block a user