diff --git a/tools/src/cli/setup.ts b/tools/src/cli/setup.ts index 887d02e1a..6a39e237d 100644 --- a/tools/src/cli/setup.ts +++ b/tools/src/cli/setup.ts @@ -41,6 +41,11 @@ export function setupCLI(): void { `Set log level (${LOG_LEVELS.join(', ')})`, 'info' ) + .option('--host', 'Expose frontend client on the local network') + .option( + '--port ', + 'Specify the port for the client dev server (default: 5173)' + ) .hook('preAction', (thisCommand, actionCommand) => { const level = thisCommand.opts().logLevel as (typeof LOG_LEVELS)[number] diff --git a/tools/src/commands/dev/functions/getConcurrentServices.ts b/tools/src/commands/dev/functions/getConcurrentServices.ts index b4a7cb3f7..ae0c50b6a 100644 --- a/tools/src/commands/dev/functions/getConcurrentServices.ts +++ b/tools/src/commands/dev/functions/getConcurrentServices.ts @@ -12,9 +12,10 @@ interface ConcurrentServiceConfig string) = string> { /** * Creates service configurations for concurrent execution */ -export default async function getConcurrentServices(): Promise< - ConcurrentServiceConfig[] -> { +export default async function getConcurrentServices( + host?: boolean, + port?: string +): Promise { const SERVICES_TO_START = ['db', 'server', 'client'] const concurrentServices: ConcurrentServiceConfig[] = [] @@ -33,9 +34,28 @@ export default async function getConcurrentServices(): Promise< getEnvVars(config.requiresEnv) } + // Add --host and --port flags for client service if provided + let finalCommand = command + + if (service === 'client') { + const args = [] + + if (host) { + args.push('--host') + } + + if (port) { + args.push('--port', port) + } + + if (args.length > 0) { + finalCommand = `${command} ${args.join(' ')}` + } + } + concurrentServices.push({ name: service, - command, + command: finalCommand, cwd }) } diff --git a/tools/src/commands/dev/functions/startServices.ts b/tools/src/commands/dev/functions/startServices.ts index 77208b14b..2bac28a30 100644 --- a/tools/src/commands/dev/functions/startServices.ts +++ b/tools/src/commands/dev/functions/startServices.ts @@ -14,7 +14,9 @@ import getConcurrentServices from './getConcurrentServices' */ export async function startSingleService( service: string, - extraArgs: string[] = [] + extraArgs: string[] = [], + host?: boolean, + port?: string ): Promise { // Handle core services if (service in SERVICE_COMMANDS) { @@ -33,7 +35,18 @@ export async function startSingleService( logger.debug(`Current Working Directory: ${chalk.blue(cwd)}`) - executeCommand(command, { cwd, stdio: 'inherit' }, extraArgs) + // Add --host and --port flags for client service if provided + const finalExtraArgs = [...extraArgs] + if (service === 'client') { + if (host) { + finalExtraArgs.push('--host') + } + if (port) { + finalExtraArgs.push('--port', port) + } + } + + executeCommand(command, { cwd, stdio: 'inherit' }, finalExtraArgs) return } @@ -53,9 +66,12 @@ export async function startSingleService( /** * Starts all development services concurrently */ -export async function startAllServices(): Promise { +export async function startAllServices( + host?: boolean, + port?: string +): Promise { try { - const concurrentServices = await getConcurrentServices() + const concurrentServices = await getConcurrentServices(host, port) const { result } = concurrently(concurrentServices, { killOthersOn: ['failure', 'success'], diff --git a/tools/src/commands/dev/handlers/devHandler.ts b/tools/src/commands/dev/handlers/devHandler.ts index 8ab816f11..31d097771 100644 --- a/tools/src/commands/dev/handlers/devHandler.ts +++ b/tools/src/commands/dev/handlers/devHandler.ts @@ -1,4 +1,5 @@ import chalk from 'chalk' +import type { Command } from 'commander' import logger from '@/utils/logger' @@ -8,10 +9,20 @@ import { startSingleService } from '../functions/startServices' -export function devHandler(service: string, extraArgs: string[] = []): void { +export function devHandler( + this: Command, + service: string, + extraArgs: string[] = [] +): void { + const options = this.parent?.opts() + + const host = options?.host + + const port = options?.port + if (!service) { logger.info('Starting all services...') - startAllServices() + startAllServices(host, port) return } @@ -28,7 +39,7 @@ export function devHandler(service: string, extraArgs: string[] = []): void { } try { - startSingleService(service, extraArgs) + startSingleService(service, extraArgs, host, port) } catch (error) { logger.error(`Failed to start ${chalk.blue(service)} service`) logger.debug(`Error details: ${error}`)