1- import { type RsbuildMode , createRsbuild } from '@rsbuild/core' ;
1+ import type { RsbuildMode } from '@rsbuild/core' ;
22import { type Command , program } from 'commander' ;
3- import { build } from '../build' ;
4- import {
5- composeRsbuildEnvironments ,
6- loadConfig ,
7- pruneEnvironments ,
8- } from '../config' ;
9- import { startMFDevServer } from '../mf' ;
103import { logger } from '../utils/logger' ;
4+ import { build } from './build' ;
5+ import { loadRslibConfig } from './init' ;
6+ import { inspect } from './inspect' ;
7+ import { startMFDevServer } from './mf' ;
118
129export type CommonOptions = {
10+ root ?: string ;
1311 config ?: string ;
1412 envMode ?: string ;
1513 lib ?: string [ ] ;
@@ -20,8 +18,8 @@ export type BuildOptions = CommonOptions & {
2018} ;
2119
2220export type InspectOptions = CommonOptions & {
23- mode : RsbuildMode ;
24- output : string ;
21+ mode ? : RsbuildMode ;
22+ output ? : string ;
2523 verbose ?: boolean ;
2624} ;
2725
@@ -31,6 +29,10 @@ const applyCommonOptions = (command: Command) => {
3129 '-c --config <config>' ,
3230 'specify the configuration file, can be a relative or absolute path' ,
3331 )
32+ . option (
33+ '-r --root <root>' ,
34+ 'specify the project root directory, can be an absolute path or a path relative to cwd' ,
35+ )
3436 . option (
3537 '--env-mode <mode>' ,
3638 'specify the env mode to load the `.env.[mode]` file' ,
@@ -60,11 +62,11 @@ export function runCli(): void {
6062 . description ( 'build the library for production' )
6163 . action ( async ( options : BuildOptions ) => {
6264 try {
63- const rslibConfig = await loadConfig ( {
64- path : options . config ,
65- envMode : options . envMode ,
65+ const rslibConfig = await loadRslibConfig ( options ) ;
66+ await build ( rslibConfig , {
67+ lib : options . lib ,
68+ watch : options . watch ,
6669 } ) ;
67- await build ( rslibConfig , options ) ;
6870 } catch ( err ) {
6971 logger . error ( 'Failed to build.' ) ;
7072 logger . error ( err ) ;
@@ -88,21 +90,12 @@ export function runCli(): void {
8890 . action ( async ( options : InspectOptions ) => {
8991 try {
9092 // TODO: inspect should output Rslib's config
91- const rslibConfig = await loadConfig ( {
92- path : options . config ,
93- envMode : options . envMode ,
94- } ) ;
95- const environments = await composeRsbuildEnvironments ( rslibConfig ) ;
96- const rsbuildInstance = await createRsbuild ( {
97- rsbuildConfig : {
98- environments : pruneEnvironments ( environments , options . lib ) ,
99- } ,
100- } ) ;
101- await rsbuildInstance . inspectConfig ( {
93+ const rslibConfig = await loadRslibConfig ( options ) ;
94+ await inspect ( rslibConfig , {
95+ lib : options . lib ,
10296 mode : options . mode ,
97+ output : options . output ,
10398 verbose : options . verbose ,
104- outputPath : options . output ,
105- writeToDisk : true ,
10699 } ) ;
107100 } catch ( err ) {
108101 logger . error ( 'Failed to inspect config.' ) ;
@@ -115,10 +108,8 @@ export function runCli(): void {
115108 . description ( 'start Rsbuild dev server of Module Federation format' )
116109 . action ( async ( options : CommonOptions ) => {
117110 try {
118- const rslibConfig = await loadConfig ( {
119- path : options . config ,
120- envMode : options . envMode ,
121- } ) ;
111+ const rslibConfig = await loadRslibConfig ( options ) ;
112+ // TODO: support lib option in mf dev server
122113 await startMFDevServer ( rslibConfig ) ;
123114 } catch ( err ) {
124115 logger . error ( 'Failed to start mf dev.' ) ;
0 commit comments