@@ -141,32 +141,40 @@ function gatherComponents(sources, components = {}) {
141
141
const names = [ ] ;
142
142
const filepaths = [ ] ;
143
143
144
- sources . forEach ( sourceDirectory =>
145
- fs . readdirSync ( sourceDirectory ) . forEach ( f => {
146
- const filepath = path . join ( sourceDirectory , f ) ;
147
- if ( fs . lstatSync ( filepath ) . isDirectory ( ) ) {
148
- gatherComponents ( f , components ) ;
149
- } else {
150
- if ( ignorePattern && ignorePattern . test ( filepath ) ) {
151
- return ;
152
- }
153
- const extension = path . extname ( filepath ) ;
154
- if ( [ '.jsx' , '.js' ] . includes ( extension ) ) {
155
- components [ cleanPath ( filepath ) ] = parseJSX ( filepath ) ;
156
- } else if ( filepath . endsWith ( '.tsx' ) ) {
157
- try {
158
- const name = / ( .* ) \. t s x / . exec ( f ) [ 1 ] ;
159
- filepaths . push ( filepath ) ;
160
- names . push ( name ) ;
161
- } catch ( err ) {
162
- process . stderr . write (
163
- `ERROR: Invalid component file ${ filepath } : ${ err } `
164
- ) ;
165
- }
166
- }
144
+ const gather = filepath => {
145
+ if ( ignorePattern && ignorePattern . test ( filepath ) ) {
146
+ return ;
147
+ }
148
+ const extension = path . extname ( filepath ) ;
149
+ if ( [ '.jsx' , '.js' ] . includes ( extension ) ) {
150
+ components [ cleanPath ( filepath ) ] = parseJSX ( filepath ) ;
151
+ } else if ( filepath . endsWith ( '.tsx' ) ) {
152
+ try {
153
+ const name = / ( .* ) \. t s x / . exec ( path . basename ( filepath ) ) [ 1 ] ;
154
+ filepaths . push ( filepath ) ;
155
+ names . push ( name ) ;
156
+ } catch ( err ) {
157
+ process . stderr . write (
158
+ `ERROR: Invalid component file ${ filepath } : ${ err } `
159
+ ) ;
167
160
}
168
- } )
169
- ) ;
161
+ }
162
+ } ;
163
+
164
+ sources . forEach ( sourcePath => {
165
+ if ( fs . lstatSync ( sourcePath ) . isDirectory ( ) ) {
166
+ fs . readdirSync ( sourcePath ) . forEach ( f => {
167
+ const filepath = path . join ( sourcePath , f ) ;
168
+ if ( fs . lstatSync ( filepath ) . isDirectory ( ) ) {
169
+ gatherComponents ( [ filepath ] , components ) ;
170
+ } else {
171
+ gather ( filepath ) ;
172
+ }
173
+ } ) ;
174
+ } else {
175
+ gather ( sourcePath ) ;
176
+ }
177
+ } ) ;
170
178
171
179
if ( ! tsEnabled ) {
172
180
return components ;
@@ -720,7 +728,7 @@ function gatherComponents(sources, components = {}) {
720
728
return components ;
721
729
}
722
730
723
- const metadata = gatherComponents ( src ) ;
731
+ const metadata = gatherComponents ( Array . isArray ( src ) ? src : [ src ] ) ;
724
732
if ( ! failedBuild ) {
725
733
process . stdout . write ( JSON . stringify ( metadata , null , 2 ) ) ;
726
734
} else {
0 commit comments