feat(admin): Improve DX for deploying admin externally (#3418)

* init deploy command

* add include flag

* add 'shortcut' flag

* add dev command, fix var replacement, change default behaviour

* cleanup params of build command

* fix defaults when using the plugin to serve admin

* add changeset

* fix globals

* update README

* throw error on no build found

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Kasper Fabricius Kristensen
2023-03-17 13:18:51 +01:00
committed by GitHub
parent 9ad15d3a88
commit 8a7421db5b
20 changed files with 358 additions and 85 deletions

View File

@@ -6,7 +6,14 @@ import { resolve } from "path"
import { loadConfig, reporter, validatePath } from "../utils"
export default async function setupAdmin() {
const { path, backend, outDir } = loadConfig()
const { path, outDir, serve, autoRebuild } = loadConfig()
// If the user has not specified that the admin UI should be served,
// we should not build it. Furthermore, if the user has not specified that they want
// the admin UI to be rebuilt on changes, we should not build it here.
if (!serve || !autoRebuild) {
return
}
try {
validatePath(path)
@@ -17,11 +24,13 @@ export default async function setupAdmin() {
let dir: string
let shouldBuild = false
/**
* If no outDir is provided we default to "build".
*/
if (outDir) {
dir = resolve(process.cwd(), outDir)
} else {
const uiPath = require.resolve("@medusajs/admin-ui")
dir = resolve(uiPath, "..", "..", "build")
dir = resolve(process.cwd(), "build")
}
try {
@@ -34,11 +43,16 @@ export default async function setupAdmin() {
const buildOptions = {
build: {
outDir: outDir,
outDir,
},
globals: {
base: path,
backend: backend,
/**
* We only build the admin UI as part of the Medusa startup process if
* the user has specified that they want to serve the admin UI. When this
* is the case, we should always set the backend to `undefined`.
*/
backend: undefined,
},
}
@@ -67,13 +81,7 @@ export default async function setupAdmin() {
)
await build({
build: {
outDir: outDir,
},
globals: {
base: path,
backend: backend,
},
...buildOptions,
}).catch((err) => {
spinner.fail(`Failed to build Admin UI${EOL}`)
reporter.panic(err)