11import * as path from "node:path" ;
22import { exec } from "node:child_process" ;
33import { promisify } from "node:util" ;
4+ import { readdirSync , existsSync } from "fs" ;
45
56const execAsync = promisify ( exec ) ;
67
@@ -15,17 +16,54 @@ export function createModuleLink(moduleName) {
1516 return `/apidocs/${ toKebabCase ( moduleName ) } ` ;
1617}
1718
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+
1852function mapRescriptFile ( file ) {
1953 const moduleName = path
2054 . basename ( file , ".res" )
2155 . replace ( "$" , "" )
2256 . replace ( "API" , " API" ) ;
57+ const filePath = path . join ( import . meta. dirname , file ) ;
2358 const link = createModuleLink ( moduleName ) ;
59+ const items = Object . fromEntries ( mapTypeModules ( link , filePath ) ) ;
60+
2461 return {
25- filePath : path . join ( import . meta . dirname , file ) ,
62+ filePath,
2663 moduleName,
2764 link,
28- apiRoute : toKebabCase ( moduleName ) ,
65+ apiRouteParameter : toKebabCase ( moduleName ) ,
66+ items,
2967 } ;
3068}
3169
0 commit comments