feat(admin,admin-ui,medusa): Add Medusa Admin plugin (#3334)
This commit is contained in:
committed by
GitHub
parent
d6b1ad1ccd
commit
40de54b010
48
packages/admin/src/commands/build.ts
Normal file
48
packages/admin/src/commands/build.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { build as buildAdmin } from "@medusajs/admin-ui"
|
||||
import ora from "ora"
|
||||
import { EOL } from "os"
|
||||
import { loadConfig, reporter, validatePath } from "../utils"
|
||||
|
||||
type BuildArgs = {
|
||||
outDir?: string
|
||||
backend?: string
|
||||
path?: string
|
||||
}
|
||||
|
||||
export default async function build(args: BuildArgs) {
|
||||
const { path, backend, outDir } = mergeArgs(args)
|
||||
|
||||
try {
|
||||
validatePath(path)
|
||||
} catch (err) {
|
||||
reporter.panic(err)
|
||||
}
|
||||
|
||||
const time = Date.now()
|
||||
const spinner = ora().start(`Building Admin UI${EOL}`)
|
||||
|
||||
await buildAdmin({
|
||||
build: {
|
||||
outDir: outDir,
|
||||
},
|
||||
globals: {
|
||||
base: path,
|
||||
backend: backend,
|
||||
},
|
||||
}).catch((err) => {
|
||||
spinner.fail(`Failed to build Admin UI${EOL}`)
|
||||
reporter.panic(err)
|
||||
})
|
||||
|
||||
spinner.succeed(`Admin UI build - ${Date.now() - time}ms`)
|
||||
}
|
||||
|
||||
const mergeArgs = (args: BuildArgs) => {
|
||||
const { path, backend, outDir } = loadConfig()
|
||||
|
||||
return {
|
||||
path: args.path || path,
|
||||
backend: args.backend || backend,
|
||||
outDir: args.outDir || outDir,
|
||||
}
|
||||
}
|
||||
15
packages/admin/src/commands/create-cli.ts
Normal file
15
packages/admin/src/commands/create-cli.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Command } from "commander"
|
||||
import build from "./build"
|
||||
|
||||
export async function createCli(): Promise<Command> {
|
||||
const program = new Command()
|
||||
|
||||
const buildCommand = program.command("build")
|
||||
buildCommand.description("Build the admin dashboard")
|
||||
buildCommand.option("-o, --out-dir <path>", "Output directory")
|
||||
buildCommand.option("-b, --backend <url>", "Backend URL")
|
||||
buildCommand.option("-p, --path <path>", "Base path")
|
||||
buildCommand.action(build)
|
||||
|
||||
return program
|
||||
}
|
||||
8
packages/admin/src/commands/index.ts
Normal file
8
packages/admin/src/commands/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createCli } from "./create-cli"
|
||||
|
||||
createCli()
|
||||
.then(async (cli) => cli.parseAsync(process.argv))
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user