@@ -105,12 +105,43 @@ export default function plugin(
105
105
} ,
106
106
} ) ;
107
107
} else {
108
- void content . map ( ( component ) =>
109
- createData (
110
- `${ component . displayName } .json` ,
111
- JSON . stringify ( component . props ) ,
112
- ) ,
108
+ const toProcess = content . reduce <
109
+ [
110
+ Record < string , string [ ] > ,
111
+ { fileName : string ; component : ComponentDoc } [ ] ,
112
+ ]
113
+ > (
114
+ ( [ processed , components ] , component ) => {
115
+ const componentName = component . displayName ;
116
+ let fileName = componentName ;
117
+ const alreadyProcessed = processed [ componentName ] ;
118
+ if ( alreadyProcessed && alreadyProcessed . length > 0 ) {
119
+ console . warn (
120
+ `Duplicate component '${ componentName } ' found (existing:
121
+ ${ alreadyProcessed [ alreadyProcessed . length - 1 ] } )` ,
122
+ ) ;
123
+
124
+ fileName += `${ alreadyProcessed . length } ` ;
125
+ console . warn (
126
+ `'${ component . filePath } ' will be written to '${ fileName } .json'` ,
127
+ ) ;
128
+ }
129
+ return [
130
+ {
131
+ ...processed ,
132
+ [ componentName ] : [
133
+ ...( alreadyProcessed || [ ] ) ,
134
+ component . filePath ,
135
+ ] ,
136
+ } ,
137
+ [ ...components , { fileName, component } ] ,
138
+ ] ;
139
+ } ,
140
+ [ { } , [ ] ] ,
113
141
) ;
142
+ toProcess [ 1 ] . forEach ( ( { fileName, component } ) => {
143
+ void createData ( `${ fileName } .json` , JSON . stringify ( component . props ) ) ;
144
+ } ) ;
114
145
}
115
146
} ,
116
147
} ;
0 commit comments