Files
medusa-store/packages/admin-ui/src/index.ts
Kasper Fabricius Kristensen 8a7421db5b 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>
2023-03-17 13:18:51 +01:00

43 lines
1.0 KiB
TypeScript

import dns from "dns"
import fse from "fs-extra"
import { resolve } from "path"
import vite from "vite"
import { AdminBuildConfig } from "./types"
import { AdminDevConfig } from "./types/dev"
import { getCustomViteConfig, getCustomViteDevConfig } from "./utils"
async function build(options?: AdminBuildConfig) {
const config = getCustomViteConfig(options)
await vite.build(config).catch((_err) => {
process.exit(1)
})
await fse.writeJSON(
resolve(config.build.outDir, "build-manifest.json"),
options
)
}
async function watch() {
throw new Error("Not implemented")
}
async function clean() {
throw new Error("Not implemented")
}
async function dev(options: AdminDevConfig) {
// Resolve localhost for Node v16 and older.
// @see https://vitejs.dev/config/server-options.html#server-host.
dns.setDefaultResultOrder("verbatim")
const server = await vite.createServer(getCustomViteDevConfig(options))
await server.listen()
server.printUrls()
}
export { build, dev, watch, clean }
export type { AdminBuildConfig, AdminDevConfig }