@@ -13,7 +13,7 @@ const data = JSON.parse(fs.readFileSync(path.join(__dirname, '../docs/data.json'
13
13
14
14
function findDtsFiles ( dir , files = [ ] ) {
15
15
// Only search in src directory
16
- const srcDir = path . join ( __dirname , '../src ' ) ;
16
+ const srcDir = path . join ( __dirname , '../types ' ) ;
17
17
if ( ! dir . startsWith ( srcDir ) ) {
18
18
dir = srcDir ;
19
19
}
@@ -26,7 +26,7 @@ function findDtsFiles(dir, files = []) {
26
26
findDtsFiles ( fullPath , files ) ;
27
27
} else if ( entry . name . endsWith ( '.d.ts' ) ) {
28
28
// Get path relative to project root and normalize to forward slashes
29
- const relativePath = path . relative ( path . join ( __dirname , '..' ) , fullPath )
29
+ const relativePath = path . relative ( path . join ( __dirname , '../types ' ) , fullPath )
30
30
. split ( path . sep )
31
31
. join ( '/' ) ;
32
32
files . push ( relativePath ) ;
@@ -37,30 +37,18 @@ function findDtsFiles(dir, files = []) {
37
37
38
38
export function generateAllDeclarationFiles ( ) {
39
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 ;
52
-
53
40
const typesDir = path . join ( process . cwd ( ) , 'types' ) ;
54
41
fs . mkdirSync ( typesDir , { recursive : true } ) ;
55
42
56
- fs . writeFileSync ( path . join ( typesDir , 'p5.d.ts' ) , p5Types , 'utf8' ) ;
57
- fs . writeFileSync ( path . join ( typesDir , 'global.d.ts' ) , globalTypes , 'utf8' ) ;
58
-
59
43
// Write file-specific type definitions
60
44
fileTypes . forEach ( ( content , filePath ) => {
61
45
const parsedPath = path . parse ( filePath ) ;
62
- const relativePath = path . relative ( process . cwd ( ) , filePath ) ;
46
+ const relativePath = path . relative (
47
+ path . join ( __dirname , "../src" ) ,
48
+ filePath
49
+ ) ;
63
50
const dtsPath = path . join (
51
+ path . relative ( process . cwd ( ) , typesDir ) ,
64
52
path . dirname ( relativePath ) ,
65
53
`${ parsedPath . name } .d.ts`
66
54
) ;
@@ -72,6 +60,21 @@ export function generateAllDeclarationFiles() {
72
60
fs . writeFileSync ( dtsPath , contentWithExport , 'utf8' ) ;
73
61
console . log ( `Generated ${ dtsPath } ` ) ;
74
62
} ) ;
63
+
64
+ // Add .d.ts references to p5Types
65
+ let p5Types = '// This file is auto-generated from JSDoc documentation\n\n' ;
66
+ p5Types += '/// <reference types="./global.d.ts" />\n' ;
67
+
68
+ // Add references to all other .d.ts files
69
+ const dtsFiles = findDtsFiles ( path . join ( __dirname , '..' ) ) ;
70
+ for ( const file of dtsFiles ) {
71
+ p5Types += `/// <reference path="./${ file } " />\n` ;
72
+ }
73
+ p5Types += '\n' ;
74
+ p5Types += rawP5Types ;
75
+
76
+ fs . writeFileSync ( path . join ( typesDir , 'p5.d.ts' ) , p5Types , 'utf8' ) ;
77
+ fs . writeFileSync ( path . join ( typesDir , 'global.d.ts' ) , globalTypes , 'utf8' ) ;
75
78
}
76
79
77
- generateAllDeclarationFiles ( ) ;
80
+ generateAllDeclarationFiles ( ) ;
0 commit comments