feat: add reusable public chrome and named environments

This commit is contained in:
2026-07-20 00:03:35 +05:30
parent f72aec7c8c
commit 1745d8d676
5 changed files with 136 additions and 58 deletions
+27 -4
View File
@@ -47,6 +47,7 @@ Usage:
Add an app to the current workspace
wrnexus gateway [--port=3000] Serve every workspace app behind one port, routed by domain
wrnexus production [workspace-dir] Build, migrate, and serve the complete production workspace
wrnexus <environment> [workspace-dir] Run a configured workspace environment (development/staging/custom)
wrnexus generate <type> <name> Scaffold a page | component | api | schema
wrnexus generate routes | docker | mobile
Generate routes or scaffold deployment targets
@@ -195,10 +196,32 @@ async function main(): Promise<void> {
case "-h":
help();
break;
default:
console.error(`Unknown command: ${command}\n`);
help();
process.exit(1);
default: {
const { loadWorkspaceConfig, runGateway, runProduction } = await import("./workspace.ts");
const workspaceRoot = rest.find((a) => !a.startsWith("--")) ?? ".";
try {
const workspace = await loadWorkspaceConfig(resolve(workspaceRoot));
const knownEnvironments = new Set([
"development",
"production",
workspace.defaultEnvironment,
...Object.keys(workspace.environments ?? {}),
]);
if (!knownEnvironments.has(command)) throw new Error("unknown-environment-command");
const environmentArgs = rest.filter((arg) => arg !== workspaceRoot);
environmentArgs.push(`--environment=${command}`);
if (command === "development") {
await runGateway(workspaceRoot, environmentArgs);
} else {
await runProduction(workspaceRoot, environmentArgs);
}
} catch (error) {
if (error instanceof Error && error.message !== "unknown-environment-command") throw error;
console.error(`Unknown command or workspace environment: ${command}\n`);
help();
process.exit(1);
}
}
}
}
+7 -1
View File
@@ -412,7 +412,12 @@ export async function runGateway(root: string, args: string[]): Promise<void> {
await startGateway({
port,
hostname,
mode: environment === "production" ? "production" : "development",
mode:
environment === "production" ||
args.includes("--prod") ||
process.env.NODE_ENV === "production"
? "production"
: "development",
environment,
security: resolved.security,
apps: resolved.apps.map((app) => ({
@@ -506,6 +511,7 @@ export async function runProduction(root: string, args: string[]): Promise<void>
if (!gatewayArgs.some((arg) => arg.startsWith("--environment="))) {
gatewayArgs.push(`--environment=${environment}`);
}
if (!gatewayArgs.includes("--prod")) gatewayArgs.push("--prod");
if (!gatewayArgs.some((arg) => arg.startsWith("--host="))) gatewayArgs.push("--host=0.0.0.0");
if (!gatewayArgs.some((arg) => arg.startsWith("--port="))) gatewayArgs.push("--port=3000");
await runGateway(workspaceRoot, gatewayArgs);