@@ -72,33 +72,41 @@ function getPriConfig(rootPath: string) {
72
72
return fs . readJsonSync ( configFilePath , { throws : false } ) || { } ;
73
73
}
74
74
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 ) ;
77
77
78
78
if ( fs . existsSync ( currentPackagesPath ) ) {
79
- globalState . packages = fs
80
- . readdirSync ( currentPackagesPath )
79
+ fs . readdirSync ( currentPackagesPath )
81
80
. filter ( folderName => {
82
81
if ( folderName === '.DS_Store' ) {
83
82
return false ;
84
83
}
85
84
86
85
return true ;
87
86
} )
88
- . map ( folderName => {
89
- const packagePath = path . join ( cliCurrentPath , PACKAGES_NAME , folderName ) ;
87
+ . forEach ( folderName => {
88
+ const packagePath = path . join ( packageRootPath , PACKAGES_NAME , folderName ) ;
90
89
const packageJson : PackageJson = fs . readJSONSync ( path . join ( packagePath , 'package.json' ) , { throws : false } ) ;
91
90
92
91
const config = fs . readJsonSync ( path . join ( packagePath , CONFIG_FILE ) , { throws : false } ) || { } ;
93
92
94
- return {
93
+ const eachPackage = {
95
94
name : folderName ,
96
95
rootPath : packagePath ,
97
96
packageJson,
98
97
config,
99
98
} ;
99
+
100
+ globalState . packages . push ( eachPackage ) ;
101
+
102
+ // find nested packages
103
+ collectPackages ( eachPackage . rootPath ) ;
100
104
} ) ;
101
105
}
106
+ }
107
+
108
+ async function initPackages ( projectRootPath : string , preSelectPackage : string ) {
109
+ collectPackages ( projectRootPath ) ;
102
110
103
111
if ( globalState . packages . length > 0 ) {
104
112
if ( ! preSelectPackage ) {
@@ -137,10 +145,12 @@ async function initPackages(cliCurrentPath: string, preSelectPackage: string) {
137
145
138
146
switch ( globalState . selectedSourceType ) {
139
147
case 'root' :
140
- globalState . sourceRoot = cliCurrentPath ;
148
+ globalState . sourceRoot = projectRootPath ;
141
149
break ;
142
150
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 ;
144
154
}
145
155
}
146
156
0 commit comments