11#!/usr/bin/env node
22import { Command } from 'commander' ;
33import chalk from 'chalk' ;
4-
4+
55import { scaffoldMonorepo , addService , scaffoldPlugin } from './lib/scaffold.js' ;
66import fs from 'fs' ;
77import path from 'path' ;
88import { renderServicesTable } from './lib/ui.js' ;
99import { runDev } from './lib/dev.js' ;
10-
10+ import { startAdminDashboard } from './lib/admin.js' ;
11+
1112const program = new Command ( ) ;
12-
13-
13+
14+
1415program
1516 . name ( 'create-polyglot' )
1617 . description ( 'Scaffold a polyglot microservice monorepo' ) ;
17-
18+
1819// New explicit init subcommand (Task: add-init-command)
1920program
2021 . command ( 'init' )
@@ -30,7 +31,7 @@ program
3031 . action ( async ( projectNameArg , options ) => {
3132 await scaffoldMonorepo ( projectNameArg , options ) ;
3233 } ) ;
33-
34+
3435// Backward compatibility: calling the root command directly still scaffolds (deprecated path).
3536program
3637 . argument ( '[project-name]' , '(Deprecated: call `create-polyglot init <name>` instead) Project name' )
@@ -49,7 +50,7 @@ program
4950 }
5051 await scaffoldMonorepo ( projectNameArg , options ) ;
5152 } ) ;
52-
53+
5354// Additional commands must be registered before final parse.
5455program
5556 . command ( 'add' )
@@ -99,15 +100,15 @@ program
99100 process . exit ( 1 ) ;
100101 }
101102 } ) ;
102-
103+
103104program
104105 . command ( 'dev' )
105106 . description ( 'Run services locally (Node & frontend) or use --docker for compose' )
106107 . option ( '--docker' , 'Use docker compose up --build to start all services' )
107108 . action ( async ( opts ) => {
108109 await runDev ( { docker : ! ! opts . docker } ) ;
109110 } ) ;
110-
111+
111112program
112113 . command ( 'services' )
113114 . description ( 'List services in the current workspace (table)' )
@@ -131,6 +132,39 @@ program
131132 process . exit ( 1 ) ;
132133 }
133134 } ) ;
134-
135+
136+ program
137+ . command ( 'admin' )
138+ . description ( 'Launch admin dashboard to monitor service status' )
139+ . option ( '-p, --port <port>' , 'Dashboard port (default: 8080)' , '8080' )
140+ . option ( '-r, --refresh <ms>' , 'Refresh interval in milliseconds (default: 5000)' , '5000' )
141+ . option ( '--no-open' , 'Don\'t auto-open browser' )
142+ . action ( async ( opts ) => {
143+ try {
144+ const port = parseInt ( opts . port ) ;
145+ const refresh = parseInt ( opts . refresh ) ;
146+
147+ if ( isNaN ( port ) || port < 1 || port > 65535 ) {
148+ console . error ( chalk . red ( 'Invalid port number. Must be between 1-65535.' ) ) ;
149+ process . exit ( 1 ) ;
150+ }
151+
152+ if ( isNaN ( refresh ) || refresh < 1000 ) {
153+ console . error ( chalk . red ( 'Invalid refresh interval. Must be at least 1000ms.' ) ) ;
154+ process . exit ( 1 ) ;
155+ }
156+
157+ await startAdminDashboard ( {
158+ port,
159+ refresh,
160+ open : opts . open
161+ } ) ;
162+ } catch ( e ) {
163+ console . error ( chalk . red ( 'Failed to start admin dashboard:' ) , e . message ) ;
164+ process . exit ( 1 ) ;
165+ }
166+ } ) ;
167+
135168program . parse ( ) ;
136-
169+
170+
0 commit comments