@@ -72,33 +72,41 @@ function getPriConfig(rootPath: string) {
7272 return fs . readJsonSync ( configFilePath , { throws : false } ) || { } ;
7373}
7474
75- async function initPackages ( cliCurrentPath : string , preSelectPackage : string ) {
76- const currentPackagesPath = path . join ( cliCurrentPath , PACKAGES_NAME ) ;
75+ function collectPackages ( packageRootPath : string ) {
76+ const currentPackagesPath = path . join ( packageRootPath , PACKAGES_NAME ) ;
7777
7878 if ( fs . existsSync ( currentPackagesPath ) ) {
79- globalState . packages = fs
80- . readdirSync ( currentPackagesPath )
79+ fs . readdirSync ( currentPackagesPath )
8180 . filter ( folderName => {
8281 if ( folderName === '.DS_Store' ) {
8382 return false ;
8483 }
8584
8685 return true ;
8786 } )
88- . map ( folderName => {
89- const packagePath = path . join ( cliCurrentPath , PACKAGES_NAME , folderName ) ;
87+ . forEach ( folderName => {
88+ const packagePath = path . join ( packageRootPath , PACKAGES_NAME , folderName ) ;
9089 const packageJson : PackageJson = fs . readJSONSync ( path . join ( packagePath , 'package.json' ) , { throws : false } ) ;
9190
9291 const config = fs . readJsonSync ( path . join ( packagePath , CONFIG_FILE ) , { throws : false } ) || { } ;
9392
94- return {
93+ const eachPackage = {
9594 name : folderName ,
9695 rootPath : packagePath ,
9796 packageJson,
9897 config,
9998 } ;
99+
100+ globalState . packages . push ( eachPackage ) ;
101+
102+ // find nested packages
103+ collectPackages ( eachPackage . rootPath ) ;
100104 } ) ;
101105 }
106+ }
107+
108+ async function initPackages ( projectRootPath : string , preSelectPackage : string ) {
109+ collectPackages ( projectRootPath ) ;
102110
103111 if ( globalState . packages . length > 0 ) {
104112 if ( ! preSelectPackage ) {
@@ -137,10 +145,12 @@ async function initPackages(cliCurrentPath: string, preSelectPackage: string) {
137145
138146 switch ( globalState . selectedSourceType ) {
139147 case 'root' :
140- globalState . sourceRoot = cliCurrentPath ;
148+ globalState . sourceRoot = projectRootPath ;
141149 break ;
142150 default :
143- globalState . sourceRoot = path . join ( cliCurrentPath , PACKAGES_NAME , globalState . selectedSourceType ) ;
151+ globalState . sourceRoot = globalState . packages . find (
152+ eachPackage => eachPackage . name === globalState . selectedSourceType ,
153+ ) . rootPath ;
144154 }
145155}
146156
0 commit comments