fix: stabilize workspace gateway and scaffolding
This commit is contained in:
@@ -13,8 +13,11 @@ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { scaffoldApp } from "./create.ts";
|
||||
import { currentCliVersion } from "./update-notifier.ts";
|
||||
import type { GatewayAuth, GatewaySecurity } from "@wrnexus/dev-server";
|
||||
|
||||
const frameworkVersion = currentCliVersion();
|
||||
|
||||
export interface WorkspaceApp {
|
||||
name: string;
|
||||
dir: string;
|
||||
@@ -29,7 +32,7 @@ export interface WorkspaceConfig {
|
||||
security?: GatewaySecurity;
|
||||
}
|
||||
|
||||
const files = (name: string): Record<string, string> => ({
|
||||
export const workspaceFiles = (name: string): Record<string, string> => ({
|
||||
"package.json": `{
|
||||
"name": "${name}",
|
||||
"private": true,
|
||||
@@ -40,7 +43,7 @@ const files = (name: string): Record<string, string> => ({
|
||||
"gateway": "wrnexus gateway"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@wrnexus/cli": "^0.2.0"
|
||||
"@wrnexus/cli": "${frameworkVersion}"
|
||||
}
|
||||
}
|
||||
`,
|
||||
@@ -86,7 +89,7 @@ dist/
|
||||
"main": "src/index.ts",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"dependencies": {
|
||||
"@wrnexus/pubsub": "^0.2.0"
|
||||
"@wrnexus/pubsub": "${frameworkVersion}"
|
||||
}
|
||||
}
|
||||
`,
|
||||
@@ -124,7 +127,7 @@ ${name}/
|
||||
|
||||
\`\`\`bash
|
||||
bun install
|
||||
bun run dev # = wrnexus gateway → http://localhost:3000
|
||||
bun run dev # = wrnexus gateway → http://127.0.0.1:3000
|
||||
\`\`\`
|
||||
|
||||
Add the hosts to your machine (e.g. /etc/hosts):
|
||||
@@ -133,6 +136,10 @@ Add the hosts to your machine (e.g. /etc/hosts):
|
||||
127.0.0.1 web.localhost admin.localhost
|
||||
\`\`\`
|
||||
|
||||
Open \`http://localhost:3000\` for the web app or
|
||||
\`http://admin.localhost:3000\` for the admin app. The ports printed for individual
|
||||
apps are internal gateway targets, not public workspace URLs.
|
||||
|
||||
## Interconnect
|
||||
|
||||
- **Shared code:** import \`@app/shared\` in any app.
|
||||
@@ -162,7 +169,7 @@ export function createWorkspace(name: string): void {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
for (const [rel, contents] of Object.entries(files(name))) {
|
||||
for (const [rel, contents] of Object.entries(workspaceFiles(name))) {
|
||||
const target = join(root, rel);
|
||||
mkdirSync(dirname(target), { recursive: true });
|
||||
writeFileSync(target, contents, "utf8");
|
||||
@@ -198,7 +205,7 @@ export async function runGateway(root: string, args: string[]): Promise<void> {
|
||||
const portArg = args.find((a) => a.startsWith("--port="));
|
||||
const hostArg = args.find((a) => a.startsWith("--host="));
|
||||
const port = portArg ? Number(portArg.split("=")[1]) : 3000;
|
||||
const hostname = hostArg?.split("=")[1] || "::";
|
||||
const hostname = hostArg?.split("=")[1];
|
||||
const mode = args.includes("--prod") ? "production" : "development";
|
||||
|
||||
const { startGateway } = await import("@wrnexus/dev-server");
|
||||
|
||||
Reference in New Issue
Block a user