@@ -22,17 +22,18 @@ function getEntries(entry) {
22
22
function getAllEntries ( arr ) {
23
23
return arr . flatMap ( getEntries ) ;
24
24
}
25
-
26
- // Organize data into structured format
27
- function organizeData ( data ) {
28
- const allData = getAllEntries ( data ) ;
29
- const organized = {
25
+ const organized = {
30
26
modules : { } ,
31
27
classes : { } ,
32
28
classitems : [ ] ,
33
29
consts : { }
34
30
} ;
35
31
32
+ // Organize data into structured format
33
+ function organizeData ( data ) {
34
+ const allData = getAllEntries ( data ) ;
35
+
36
+
36
37
// Process modules first
37
38
allData . forEach ( entry => {
38
39
if ( entry . tags ?. some ( tag => tag . title === 'module' ) ) {
@@ -52,8 +53,9 @@ function organizeData(data) {
52
53
allData . forEach ( entry => {
53
54
if ( entry . kind === 'class' ) {
54
55
const { module, submodule } = getModuleInfo ( entry ) ;
55
- organized . classes [ entry . name ] = {
56
- name : entry . name ,
56
+ const className = entry . name ;
57
+ organized . classes [ className ] = {
58
+ name : className ,
57
59
description : extractDescription ( entry . description ) ,
58
60
params : ( entry . params || [ ] ) . map ( param => ( {
59
61
name : param . name ,
@@ -70,9 +72,11 @@ function organizeData(data) {
70
72
allData . forEach ( entry => {
71
73
if ( entry . kind === 'function' || entry . kind === 'property' ) {
72
74
const { module, submodule, forEntry } = getModuleInfo ( entry ) ;
73
- const className = forEntry || 'p5' ;
74
-
75
- if ( ! organized . classes [ className ] ) return ;
75
+ // Use memberof if available, fallback to forEntry, then default to 'p5'
76
+ const className = entry . memberof || forEntry || 'p5' ;
77
+
78
+ // Create the class entry if it doesn't exist
79
+ // if (!organized.classes[className]) {console.log(`returning for ${className}`); return};
76
80
77
81
// Check for static methods - directly check path[0].scope
78
82
// Todo: handle static methods
@@ -117,6 +121,7 @@ function organizeData(data) {
117
121
class : forEntry || 'p5'
118
122
} ;
119
123
}
124
+ fs . writeFileSync ( "./consts.json" , JSON . stringify ( organized . consts , null , 2 ) , 'utf8' ) ;
120
125
} ) ;
121
126
122
127
return organized ;
@@ -308,10 +313,6 @@ function generateClassDeclaration(classDoc, organizedData) {
308
313
output += ' */\n' ;
309
314
}
310
315
311
- // Generate class declaration
312
- const isAbstract = classDoc . tags ?. some ( t => t . title === 'abstract' ) ;
313
- output += `${ isAbstract ? 'abstract ' : '' } class ${ classDoc . name . replace ( 'p5.' , '' ) } {\n` ;
314
-
315
316
// Add constructor if there are parameters
316
317
if ( classDoc . params ?. length > 0 ) {
317
318
output += ' constructor(' ;
@@ -322,8 +323,8 @@ function generateClassDeclaration(classDoc, organizedData) {
322
323
}
323
324
324
325
// Get all class items for this class
325
- const classItems = organizedData . classitems . filter ( item => item . class === classDoc . name ) ;
326
-
326
+ const classDocName = classDoc . name . startsWith ( 'p5.' ) ? classDoc . name . substring ( 3 ) : classDoc . name ;
327
+ const classItems = organizedData . classitems . filter ( item => item . class === classDocName ) ;
327
328
328
329
// Separate static and instance members
329
330
const staticItems = classItems . filter ( item => item . isStatic ) ;
@@ -362,14 +363,14 @@ function generateClassDeclaration(classDoc, organizedData) {
362
363
const returnType = overload . returns ?. [ 0 ] ?. type
363
364
? generateTypeFromTag ( overload . returns [ 0 ] )
364
365
: 'void' ;
365
- output += ` static function ${ item . name } (${ params } ): ${ returnType } ;\n` ;
366
+ output += ` static ${ item . name } (${ params } ): ${ returnType } ;\n` ;
366
367
} ) ;
367
368
output += '\n' ;
368
369
} else {
369
370
const params = ( item . params || [ ] )
370
371
. map ( param => generateParamDeclaration ( param ) )
371
372
. join ( ', ' ) ;
372
- output += ` static function ${ item . name } (${ params } ): ${ item . returnType } ;\n\n` ;
373
+ output += ` static ${ item . name } (${ params } ): ${ item . returnType } ;\n\n` ;
373
374
}
374
375
} else {
375
376
output += ` static ${ item . name } : ${ item . returnType } ;\n\n` ;
@@ -538,7 +539,7 @@ function generateAllDeclarationFiles() {
538
539
) ;
539
540
540
541
// Generate the declaration file content
541
- const declarationContent = generateDeclarationFile ( items , filePath , organizedData ) ;
542
+ const declarationContent = generateDeclarationFile ( items , filePath , organized ) ;
542
543
543
544
// Create directory if it doesn't exist
544
545
fs . mkdirSync ( path . dirname ( dtsPath ) , { recursive : true } ) ;
0 commit comments