Skip to content

Commit 5168499

Browse files
committed
refactor(serve): enhance Studio UI option handling and remove Vite dev server fallback
1 parent 09d50fd commit 5168499

1 file changed

Lines changed: 7 additions & 25 deletions

File tree

packages/cli/src/commands/serve.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {
1818
STUDIO_PATH,
1919
resolveStudioPath,
2020
hasStudioDist,
21-
spawnViteDevServer,
22-
createStudioProxyPlugin,
2321
createStudioStaticPlugin,
2422
} from '../utils/studio.js';
2523

@@ -53,7 +51,7 @@ export const serveCommand = new Command('serve')
5351
.argument('[config]', 'Configuration file path', 'objectstack.config.ts')
5452
.option('-p, --port <port>', 'Server port', '3000')
5553
.option('--dev', 'Run in development mode (load devPlugins)')
56-
.option('--ui', 'Enable Studio UI at /_studio/')
54+
.option('--ui', 'Enable Studio UI at /_studio/ (default: true in dev mode)')
5755
.option('--no-server', 'Skip starting HTTP server plugin')
5856
.action(async (configPath, options) => {
5957
let port = parseInt(options.port);
@@ -246,31 +244,19 @@ export const serveCommand = new Command('serve')
246244
}
247245
}
248246

249-
// ── Studio UI (--ui) ────────────────────────────────────────────
250-
// Strategy: always prefer pre-built dist/ if it exists (fast, no
251-
// extra process). Only fall back to Vite dev server when dist is
252-
// missing AND we're in dev mode.
253-
let viteProcess: import('child_process').ChildProcess | null = null;
247+
// ── Studio UI ─────────────────────────────────────────────────
248+
// In dev mode, Studio UI is enabled by default (use --no-ui to disable).
249+
// Always serves the pre-built dist/ — no Vite dev server, no extra port.
250+
const enableUI = options.ui ?? isDev;
254251

255-
if (options.ui) {
252+
if (enableUI) {
256253
const studioPath = resolveStudioPath();
257254
if (!studioPath) {
258255
console.warn(chalk.yellow(` ⚠ @objectstack/studio not found — skipping UI`));
259256
} else if (hasStudioDist(studioPath)) {
260-
// Serve pre-built static files (works in both dev & production)
261257
const distPath = path.join(studioPath, 'dist');
262258
await kernel.use(createStudioStaticPlugin(distPath));
263259
trackPlugin('StudioUI');
264-
} else if (isDev) {
265-
// Fallback: dist not built yet → spawn Vite dev server
266-
try {
267-
const result = await spawnViteDevServer(studioPath, { serverPort: port });
268-
viteProcess = result.process;
269-
await kernel.use(createStudioProxyPlugin(result.port));
270-
trackPlugin('StudioUI');
271-
} catch (e: any) {
272-
console.warn(chalk.yellow(` ⚠ Studio UI failed to start: ${e.message}`));
273-
}
274260
} else {
275261
console.warn(chalk.yellow(` ⚠ Studio dist not found — run "pnpm --filter @objectstack/studio build" first`));
276262
}
@@ -290,17 +276,13 @@ export const serveCommand = new Command('serve')
290276
isDev,
291277
pluginCount: loadedPlugins.length,
292278
pluginNames: loadedPlugins,
293-
uiEnabled: !!options.ui,
279+
uiEnabled: enableUI,
294280
studioPath: STUDIO_PATH,
295281
});
296282

297283
// Keep process alive
298284
process.on('SIGINT', async () => {
299285
console.warn(chalk.yellow(`\n\n⏹ Stopping server...`));
300-
if (viteProcess) {
301-
viteProcess.kill();
302-
viteProcess = null;
303-
}
304286
await runtime.getKernel().shutdown();
305287
console.log(chalk.green(`✅ Server stopped`));
306288
process.exit(0);

0 commit comments

Comments
 (0)