feat(admin,admin-ui,medusa): Add Medusa Admin plugin (#3334)
This commit is contained in:
committed by
GitHub
parent
d6b1ad1ccd
commit
40de54b010
3
packages/admin/src/utils/index.ts
Normal file
3
packages/admin/src/utils/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { loadConfig } from "./load-config"
|
||||
export { reporter } from "./reporter"
|
||||
export { validatePath } from "./validate-path"
|
||||
32
packages/admin/src/utils/load-config.ts
Normal file
32
packages/admin/src/utils/load-config.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
import { ConfigModule, PluginOptions } from "../types"
|
||||
|
||||
export const loadConfig = () => {
|
||||
const { configModule } = getConfigFile<ConfigModule>(
|
||||
process.cwd(),
|
||||
"medusa-config"
|
||||
)
|
||||
|
||||
const plugin = configModule.plugins.find(
|
||||
(p) =>
|
||||
(typeof p === "string" && p === "@medusajs/admin") ||
|
||||
(typeof p === "object" && p.resolve === "@medusajs/admin")
|
||||
)
|
||||
|
||||
let defaultConfig: PluginOptions = {
|
||||
serve: true,
|
||||
path: "app",
|
||||
}
|
||||
|
||||
if (typeof plugin !== "string") {
|
||||
const { options } = plugin as { options: PluginOptions }
|
||||
defaultConfig = {
|
||||
serve: options.serve ?? defaultConfig.serve,
|
||||
path: options.path ?? defaultConfig.path,
|
||||
backend: options.backend ?? defaultConfig.backend,
|
||||
outDir: options.outDir ?? defaultConfig.outDir,
|
||||
}
|
||||
}
|
||||
|
||||
return defaultConfig
|
||||
}
|
||||
19
packages/admin/src/utils/reporter.ts
Normal file
19
packages/admin/src/utils/reporter.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import colors from "picocolors"
|
||||
|
||||
const PREFIX = colors.cyan("[@medusajs/admin]")
|
||||
|
||||
export const reporter = {
|
||||
panic: (err: Error) => {
|
||||
console.error(`${PREFIX} ${colors.red(err.message)}`)
|
||||
process.exit(1)
|
||||
},
|
||||
error: (message: string) => {
|
||||
console.error(`${PREFIX} ${colors.red(message)}`)
|
||||
},
|
||||
info: (message: string) => {
|
||||
console.log(`${PREFIX} ${colors.blue(message)}`)
|
||||
},
|
||||
warn: (message: string) => {
|
||||
console.warn(`${PREFIX} ${colors.yellow(message)}`)
|
||||
},
|
||||
}
|
||||
15
packages/admin/src/utils/validate-path.ts
Normal file
15
packages/admin/src/utils/validate-path.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export const validatePath = (path: string) => {
|
||||
if (path.startsWith("/")) {
|
||||
throw new Error(`Path cannot start with a slash.`)
|
||||
}
|
||||
|
||||
if (path.endsWith("/")) {
|
||||
throw new Error(`Path cannot end with a slash.`)
|
||||
}
|
||||
|
||||
if (path === "admin" || path === "store") {
|
||||
throw new Error(
|
||||
`Path cannot be one of the reserved paths: "admin", "store".`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user