11import chokidar from 'chokidar' ;
22import path from 'node:path' ;
33import fs from 'node:fs/promises' ;
4- import fss from 'node:fs' ; // NEW: for createReadStream
4+ import fss from 'node:fs' ;
55import crypto from 'node:crypto' ;
6- import http from 'node:http' ; // NEW: tiny HTTP server
7- import { fileURLToPath } from 'node:url' ; // NEW: resolve UI dist
6+ import http from 'node:http' ;
7+ import { fileURLToPath } from 'node:url' ;
88
99import { loadConfig } from '../config/loadConfig.js' ;
1010import { loadModuleValue } from '../loader/loadModuleValue.js' ;
@@ -72,13 +72,11 @@ export default async function devCmd(argv) {
7272 const { config } = await loadConfig ( { flags } ) ;
7373
7474 // Where to notify preview
75- // NEW: dev server + UI defaults
7675 const host = String ( flags . host ?? '127.0.0.1' ) ;
7776 const port = Number . isFinite ( flags . port ) ? Number ( flags . port ) : 8788 ;
7877 const noUi = ! ! ( flags [ 'no-ui' ] || flags . noUi ) ;
7978 const noOpen = ! ! ( flags [ 'no-open' ] || flags . noOpen ) ;
8079
81- // NEW: live SSE clients
8280 const sseClients = new Set ( ) ; // each entry: { id, res }
8381 function sseBroadcast ( msg ) {
8482 const line = `data: ${ msg } \n\n` ;
@@ -274,7 +272,6 @@ export default async function devCmd(argv) {
274272 await writeManifest ( ) ;
275273 console . log ( `[statikapi] ready. Watching ${ path . relative ( process . cwd ( ) , config . paths . srcAbs ) } /` ) ;
276274
277- // NEW: start HTTP server (UI + JSON helpers + SSE)
278275 const server = http . createServer ( async ( req , res ) => {
279276 try {
280277 let url ;
@@ -286,7 +283,6 @@ export default async function devCmd(argv) {
286283 }
287284 const pathname = url . pathname ;
288285
289- // 1) SSE: /_ui/events
290286 if ( pathname === '/_ui/events' ) {
291287 res . writeHead ( 200 , {
292288 'Content-Type' : 'text/event-stream' ,
@@ -301,7 +297,6 @@ export default async function devCmd(argv) {
301297 return ;
302298 }
303299
304- // 2) Manifest JSON for UI: /ui/index
305300 if ( pathname === '/ui/index' && req . method === 'GET' ) {
306301 const list = Array . from ( manifestByRoute . values ( ) ) . sort ( ( a , b ) =>
307302 a . route . localeCompare ( b . route )
@@ -312,7 +307,6 @@ export default async function devCmd(argv) {
312307 return ;
313308 }
314309
315- // 3) Serve built file content: /_ui/file?route=/path
316310 if ( pathname === '/_ui/file' && req . method === 'GET' ) {
317311 const route = url . searchParams . get ( 'route' ) || '' ;
318312 const outFile = routeToOutPath ( { outAbs : config . paths . outAbs , route } ) ;
@@ -332,7 +326,6 @@ export default async function devCmd(argv) {
332326 return ;
333327 }
334328
335- // 4) Static React UI at /_ui/* (unless --no-ui)
336329 if ( ! noUi && pathname . startsWith ( '/_ui/' ) ) {
337330 const uiRoot = resolveUiDist ( ) ;
338331 const rel = pathname . replace ( / ^ \/ _ u i \/ / , '' ) || 'index.html' ;
@@ -360,14 +353,13 @@ export default async function devCmd(argv) {
360353 return ;
361354 }
362355
363- // 5) Root → redirect to UI (unless --no-ui)
364356 if ( ! noUi && pathname === '/' ) {
365357 res . writeHead ( 302 , { Location : '/_ui/' } ) ;
366358 res . end ( ) ;
367359 return ;
368360 }
369361
370- // 6) Serve built JSON directly from api-out
362+ // Serve built JSON directly from api-out
371363 {
372364 const outRoot = config . paths . outAbs ;
373365 // strip leading slash and normalize
@@ -439,7 +431,6 @@ export default async function devCmd(argv) {
439431 return 0 ;
440432}
441433
442- // NEW: helpers (static file & UI dist resolver & opener)
443434function streamFile ( file , res ) {
444435 const ext = path . extname ( file ) . toLowerCase ( ) ;
445436 const ctype =
@@ -461,19 +452,19 @@ function streamFile(file, res) {
461452}
462453
463454function resolveUiDist ( ) {
464- // 0) Optional override for power users
455+ // Optional override for power users
465456 const fromEnv = process . env . STATIKAPI_UI_DIR ;
466457 if ( fromEnv && hasIndex ( fromEnv ) ) return fromEnv ;
467458
468- // 1) Bundled with the CLI: packages/cli/ui/ (your screenshot)
459+ // Bundled with the CLI: packages/cli/ui/
469460 const bundled = path . resolve ( __dirname , '..' , '..' , 'ui' ) ;
470461 if ( hasIndex ( bundled ) ) return bundled ;
471462
472- // 2) Monorepo dev fallback: packages/ui/dist
463+ // Monorepo dev fallback: packages/ui/dist
473464 const monorepoDist = path . resolve ( __dirname , '..' , '..' , '..' , 'ui' , 'dist' ) ;
474465 if ( hasIndex ( monorepoDist ) ) return monorepoDist ;
475466
476- // 3) Last resort: throw with a helpful hint
467+ // Last resort: throw with a helpful hint
477468 throw new Error (
478469 'StatikAPI UI build not found. ' +
479470 'Either keep a built UI at packages/cli/ui/ (index.html present), ' +
0 commit comments