@@ -5,48 +5,26 @@ import { appCommands } from './app';
55import { bundleCommands } from './bundle' ;
66import { diffCommands } from './diff' ;
77import { installCommands } from './install' ;
8- import { moduleManager } from './module-manager' ;
9- import { builtinModules } from './modules' ;
108import { packageCommands } from './package' ;
11- import type { CommandContext } from './types' ;
129import { userCommands } from './user' ;
1310import { printVersionCommand } from './utils' ;
1411import { t } from './utils/i18n' ;
1512import { versionCommands } from './versions' ;
1613
17- type LegacyCommandHandler = ( argv : any ) => Promise < unknown > | unknown ;
14+ type CliCommandHandler = ( argv : any ) => Promise < unknown > | unknown ;
1815
1916interface CliArgv {
2017 command: string ;
2118 args: string [ ] ;
2219 options: Record < string , any > ;
2320}
2421
25- function registerBuiltinModules ( ) {
26- for ( const module of builtinModules ) {
27- try {
28- moduleManager . registerModule ( module ) ;
29- } catch ( error ) {
30- console . error ( `Failed to register module ${ module . name } :` , error ) ;
31- }
32- }
33- }
34-
35- function printUsage ( ) {
22+ function printUsage ( exitCode = 1 ) {
3623 console . log ( 'React Native Update CLI' ) ;
3724 console . log ( '' ) ;
38- console . log ( 'Traditional commands:' ) ;
39- for ( const name of Object . keys ( legacyCommands ) ) {
40- console . log ( ` ${ name } : Legacy command` ) ;
41- }
42-
43- console . log ( '' ) ;
44- console . log ( 'Modular commands:' ) ;
45- const commands = moduleManager . listCommands ( ) ;
46- for ( const command of commands ) {
47- console . log (
48- ` ${ command . name } : ${ command . description || 'No description' } ` ,
49- ) ;
25+ console . log ( 'Commands:' ) ;
26+ for ( const name of Object . keys ( commandHandlers ) ) {
27+ console . log ( ` ${ name } ` ) ;
5028 }
5129
5230 console . log ( '' ) ;
@@ -58,10 +36,10 @@ function printUsage() {
5836 console . log (
5937 'Visit `https://github.com/reactnativecn/react-native-update` for document.' ,
6038 ) ;
61- process . exit ( 1 ) ;
39+ process . exit ( exitCode ) ;
6240}
6341
64- const legacyCommands : Record < string , LegacyCommandHandler > = {
42+ const commandHandlers : Record < string , CliCommandHandler > = {
6543 ...userCommands ,
6644 ...bundleCommands ,
6745 ...diffCommands ,
@@ -78,41 +56,22 @@ async function run() {
7856 process . exit ( ) ;
7957 }
8058
81- // Register builtin modules for modular functionality
82- registerBuiltinModules ( ) ;
83-
8459 const argv : CliArgv = require ( 'cli-arguments' ) . parse ( require ( '../cli.json' ) ) ;
8560 global . NO_INTERACTIVE = argv . options [ 'no-interactive' ] ;
8661 global . USE_ACC_OSS = argv . options . acc ;
8762
88- const context : CommandContext = {
89- args : argv . args || [ ] ,
90- options : argv . options || { } ,
91- } ;
92-
9363 try {
9464 await loadSession ( ) ;
95- context . session = require ( './api' ) . getSession ( ) ;
9665
97- // Handle special modular commands first
9866 if ( argv . command === 'help' ) {
99- printUsage ( ) ;
67+ printUsage ( 0 ) ;
10068 } else if ( argv . command === 'list' ) {
101- moduleManager . listAll ( ) ;
102- }
103- // Try legacy commands first for backward compatibility
104- else if ( legacyCommands [ argv . command ] ) {
105- const legacyHandler = legacyCommands [ argv . command ] ;
106- await legacyHandler ( argv ) ;
107- }
108- // Fall back to modular commands
109- else {
110- const result = await moduleManager . executeCommand ( argv . command , context ) ;
111- if ( ! result . success ) {
112- console . error ( 'Command execution failed:' , result . error ) ;
113- process . exit ( 1 ) ;
114- }
115- console . log ( 'Command completed successfully:' , result . data ) ;
69+ printUsage ( 0 ) ;
70+ } else if ( commandHandlers [ argv . command ] ) {
71+ const handler = commandHandlers [ argv . command ] ;
72+ await handler ( argv ) ;
73+ } else {
74+ throw new Error ( `Unknown command: ${ argv . command } ` ) ;
11675 }
11776 } catch ( err : any ) {
11877 if ( err . status === 401 ) {
@@ -124,12 +83,12 @@ async function run() {
12483 }
12584}
12685
86+ export { moduleManager } from './module-manager' ;
12787export { CLIProviderImpl } from './provider' ;
12888export type {
12989 CLIModule ,
13090 CLIProvider ,
13191 CommandDefinition ,
13292} from './types' ;
133- export { moduleManager } ;
13493
13594run ( ) ;
0 commit comments