@@ -11,8 +11,44 @@ const __dirname = path.dirname(__filename);
11
11
12
12
const data = JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../docs/data.json' ) ) ) ;
13
13
14
+ function findDtsFiles ( dir , files = [ ] ) {
15
+ // Only search in src directory
16
+ const srcDir = path . join ( __dirname , '../src' ) ;
17
+ if ( ! dir . startsWith ( srcDir ) ) {
18
+ dir = srcDir ;
19
+ }
20
+
21
+ const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
22
+
23
+ for ( const entry of entries ) {
24
+ const fullPath = path . join ( dir , entry . name ) ;
25
+ if ( entry . isDirectory ( ) ) {
26
+ findDtsFiles ( fullPath , files ) ;
27
+ } else if ( entry . name . endsWith ( '.d.ts' ) ) {
28
+ // Get path relative to project root and normalize to forward slashes
29
+ const relativePath = path . relative ( path . join ( __dirname , '..' ) , fullPath )
30
+ . split ( path . sep )
31
+ . join ( '/' ) ;
32
+ files . push ( relativePath ) ;
33
+ }
34
+ }
35
+ return files ;
36
+ }
37
+
14
38
export function generateAllDeclarationFiles ( ) {
15
- const { p5Types, globalTypes, fileTypes } = generateTypeDefinitions ( data ) ;
39
+ const { p5Types : rawP5Types , globalTypes, fileTypes } = generateTypeDefinitions ( data ) ;
40
+
41
+ // Add .d.ts references to p5Types
42
+ let p5Types = '// This file is auto-generated from JSDoc documentation\n\n' ;
43
+ p5Types += '/// <reference types="./global.d.ts" />\n' ;
44
+
45
+ // Add references to all other .d.ts files
46
+ const dtsFiles = findDtsFiles ( path . join ( __dirname , '..' ) ) ;
47
+ for ( const file of dtsFiles ) {
48
+ p5Types += `/// <reference path="../${ file } " />\n` ;
49
+ }
50
+ p5Types += '\n' ;
51
+ p5Types += rawP5Types ;
16
52
17
53
const typesDir = path . join ( process . cwd ( ) , 'types' ) ;
18
54
fs . mkdirSync ( typesDir , { recursive : true } ) ;
0 commit comments