1
1
import * as path from "node:path" ;
2
2
import { exec } from "node:child_process" ;
3
3
import { promisify } from "node:util" ;
4
+ import { readdirSync , existsSync } from "fs" ;
4
5
5
6
const execAsync = promisify ( exec ) ;
6
7
@@ -15,17 +16,54 @@ export function createModuleLink(moduleName) {
15
16
return `/apidocs/${ toKebabCase ( moduleName ) } ` ;
16
17
}
17
18
19
+ function mapTypeModules ( parentModuleLink , file ) {
20
+ const folder = file . replace ( ".res" , "" ) ;
21
+
22
+ if ( ! existsSync ( folder ) ) {
23
+ return [ ] ;
24
+ }
25
+
26
+ const files = readdirSync ( folder ) ;
27
+ return files
28
+ . filter ( ( f ) => f . endsWith ( ".res" ) )
29
+ . map ( ( file ) => {
30
+ const fullPath = path . join ( folder , file ) ;
31
+
32
+ const moduleName = file
33
+ . replace ( "$" , "" )
34
+ . replace ( folder , "" )
35
+ . replace ( ".res" , "" ) ;
36
+ const apiRouteParameter = toKebabCase ( moduleName ) ;
37
+ const link = `${ parentModuleLink } /${ apiRouteParameter } ` ;
38
+ const typeName = moduleName [ 0 ] . toLocaleLowerCase ( ) + moduleName . slice ( 1 ) ;
39
+
40
+ return [
41
+ typeName ,
42
+ {
43
+ fullPath,
44
+ moduleName,
45
+ link,
46
+ apiRouteParameter,
47
+ } ,
48
+ ] ;
49
+ } ) ;
50
+ }
51
+
18
52
function mapRescriptFile ( file ) {
19
53
const moduleName = path
20
54
. basename ( file , ".res" )
21
55
. replace ( "$" , "" )
22
56
. replace ( "API" , " API" ) ;
57
+ const filePath = path . join ( import . meta. dirname , file ) ;
23
58
const link = createModuleLink ( moduleName ) ;
59
+ const items = Object . fromEntries ( mapTypeModules ( link , filePath ) ) ;
60
+
24
61
return {
25
- filePath : path . join ( import . meta . dirname , file ) ,
62
+ filePath,
26
63
moduleName,
27
64
link,
28
- apiRoute : toKebabCase ( moduleName ) ,
65
+ apiRouteParameter : toKebabCase ( moduleName ) ,
66
+ items,
29
67
} ;
30
68
}
31
69
0 commit comments