@@ -191,12 +191,29 @@ const STANDARD_MAT_PROPS = [
191
191
const REPLACEMENTS = [ {
192
192
path : `${ TYPES_PATH } /scene/materials/standard-material.d.ts` ,
193
193
replacement : {
194
- from : 'reset(): void;' ,
195
- to : `reset(): void;
196
- ${ STANDARD_MAT_PROPS . map ( prop => `
197
- set ${ prop [ 0 ] } (arg: ${ prop [ 1 ] } );
198
- get ${ prop [ 0 ] } (): ${ prop [ 1 ] } ;
199
- ` ) . join ( '' ) } `,
194
+ transformer : ( contents ) => {
195
+
196
+ // Find the jsdoc block description using eg "@property {Type} {name}"
197
+ return contents . replace ( 'reset(): void;' , `reset(): void;
198
+ ${ STANDARD_MAT_PROPS . map ( prop => {
199
+ const typeDefinition = `@property {${ prop [ 1 ] } } ${ prop [ 0 ] } `
200
+ const typeDescriptionIndex = contents . match ( typeDefinition ) ;
201
+ const typeDescription = typeDescriptionIndex ?
202
+ contents . slice ( typeDescriptionIndex . index + typeDefinition . length , contents . indexOf ( '\n * @property' , typeDescriptionIndex . index + typeDefinition . length ) )
203
+ : '' ;
204
+
205
+ // Strip newlines, asterisks, and tabs from the type description
206
+ const cleanTypeDescription = typeDescription
207
+ . trim ( )
208
+ . replace ( / [ \n \t * ] / g, ' ' ) // remove newlines, tabs, and asterisks
209
+ . replace ( / \s + / g, ' ' ) ; // collapse whitespace
210
+
211
+ const jsdoc = cleanTypeDescription ? `/** ${ cleanTypeDescription } */` : '' ;
212
+ // console.log(prop[0], contents.match(`@property {${prop[1]}} ${prop[0]}`), cleanTypeDescription);
213
+ return `\t${ jsdoc } \n\tset ${ prop [ 0 ] } (arg: ${ prop [ 1 ] } );\n\tget ${ prop [ 0 ] } (): ${ prop [ 1 ] } ;\n\n` ;
214
+ } ) . join ( '' ) } `,
215
+ )
216
+ } ,
200
217
footer : `
201
218
import { Color } from '../../core/math/color.js';
202
219
import { Vec2 } from '../../core/math/vec2.js';
@@ -243,9 +260,13 @@ export function typesFixup() {
243
260
name : 'types-fixup' ,
244
261
buildStart ( ) {
245
262
REPLACEMENTS . forEach ( ( item ) => {
246
- const { from, to, footer } = item . replacement ;
263
+ const { from, to, footer, transformer } = item . replacement ;
247
264
let contents = fs . readFileSync ( item . path , 'utf-8' ) ;
248
- contents = contents . replace ( from , to ) ;
265
+ if ( transformer ) {
266
+ contents = transformer ( contents ) ;
267
+ } else {
268
+ contents = contents . replace ( from , to ) ;
269
+ }
249
270
contents += footer ?? '' ;
250
271
fs . writeFileSync ( item . path , contents , 'utf-8' ) ;
251
272
console . log ( `${ GREEN_OUT } type fixed ${ BOLD_OUT } ${ item . path } ${ REGULAR_OUT } ` ) ;
0 commit comments