UNPKG

@gez/core

Version:

A high-performance microfrontend framework supporting Vue, React, Preact, Solid, and Svelte with SSR and Module Federation capabilities.

74 lines (73 loc) 2.02 kB
import module from "node:module"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { COMMAND, Gez } from "../gez.mjs"; async function getSrcOptions() { return import(path.resolve(process.cwd(), "./src/entry.node.ts")).then( (m) => m.default ); } export async function cli(command) { if (command !== COMMAND.dev) { process.env.NODE_ENV = "production"; } let gez; let opts = null; switch (command) { case COMMAND.dev: opts = await getSrcOptions(); gez = new Gez(opts); exit(await gez.init(COMMAND.dev)); gez = null; opts = null; break; case COMMAND.start: throw new Error( `Please use 'NODE_ENV=production node dist/index.js' to run the built program` ); case COMMAND.build: opts = await getSrcOptions(); gez = new Gez(opts); exit(await gez.init(COMMAND.build)); exit(await gez.destroy()); if (typeof opts.postBuild === "function") { gez = new Gez({ ...opts, server: void 0 }); exit(await gez.init(COMMAND.start)); exit(await gez.postBuild()); } gez = null; opts = null; break; case COMMAND.preview: opts = await getSrcOptions(); gez = new Gez(opts); exit(await gez.init(COMMAND.build)); exit(await gez.destroy()); gez = new Gez(opts); exit(await gez.init(COMMAND.start)); exit(await gez.postBuild()); gez = null; opts = null; break; default: await import(path.resolve(process.cwd(), command)); break; } } function exit(ok) { if (!ok) { process.exit(17); } } module.register(fileURLToPath(import.meta.url), { parentURL: import.meta.url }); export function resolve(specifier, context, nextResolve) { if (context?.parentURL.endsWith(".ts") && specifier.startsWith(".") && !specifier.endsWith(".ts")) { return nextResolve(specifier + ".ts", context); } return nextResolve(specifier, context); }